Add horizontal scrollbar to Fl_Help_View.

Tweek table "squeezing" code.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1715 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 2001-11-24 04:12:56 +00:00
parent 70abac1b8b
commit e016a249b2
4 changed files with 731 additions and 594 deletions

View File

@ -10,6 +10,8 @@ CHANGES IN FLTK 1.1.0b6
- Added new Fl_Shared_Image class, a la FLTK 2.0.
- Added new copy(), desaturate(), inactive(), and
color_average() methods to the Fl_Image classes.
- Added a horizontal scrollbar to the Fl_Help_View
widget.
- Fl_Float_Input and Fl_Int_Input no longer accept
pasted text that is not a floating point or integer
value. Pasted numbers now replace text in these

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Help_View.H,v 1.1.2.4 2001/11/24 02:46:19 easysw Exp $"
// "$Id: Fl_Help_View.H,v 1.1.2.5 2001/11/24 04:12:56 easysw Exp $"
//
// Help Viewer widget definitions.
//
@ -126,8 +126,11 @@ class Fl_Help_View : public Fl_Group //// Help viewer widget
char directory_[1024]; // Directory for current file
char filename_[1024]; // Current filename
int topline_, // Top line in document
size_; // Total document length
Fl_Scrollbar scrollbar_; // Vertical scrollbar for document
leftline_, // Lefthand position
size_, // Total document length
hsize_; // Maximum document width
Fl_Scrollbar scrollbar_, // Vertical scrollbar for document
hscrollbar_; // Horizontal scrollbar
Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
static int compare_blocks(const void *a, const void *b);
@ -142,6 +145,7 @@ class Fl_Help_View : public Fl_Group //// Help viewer widget
const char *get_attr(const char *p, const char *n, char *buf, int bufsize);
Fl_Color get_color(const char *n, Fl_Color c);
Fl_Shared_Image *get_image(const char *name, int W, int H);
int get_length(const char *l);
int handle(int);
void initfont(uchar &f, uchar &s) { nfonts_ = 0;
@ -176,6 +180,8 @@ class Fl_Help_View : public Fl_Group //// Help viewer widget
void topline(const char *n);
void topline(int);
int topline() const { return (topline_); }
void leftline(int);
int leftline() const { return (leftline_); }
void value(const char *v);
const char *value() const { return (value_); }
};
@ -183,5 +189,5 @@ class Fl_Help_View : public Fl_Group //// Help viewer widget
#endif // !Fl_Help_View_H
//
// End of "$Id: Fl_Help_View.H,v 1.1.2.4 2001/11/24 02:46:19 easysw Exp $".
// End of "$Id: Fl_Help_View.H,v 1.1.2.5 2001/11/24 04:12:56 easysw Exp $".
//

View File

@ -49,4 +49,5 @@ Fl_Value_Slider::textfont() const
<H4><A name=Fl_Value_Slider.textsize>uchar Fl_Value_Slider::textsize()
const
<BR> void Fl_Value_Slider::textsize(uchar)</A></H4>
Gets or sets the size of the text in the value box. </BODY></HTML>
Gets or sets the size of the text in the value box.
</BODY></HTML>

View File

@ -1,5 +1,5 @@
//
// "$Id: Fl_Help_View.cxx,v 1.1.2.13 2001/11/24 02:46:19 easysw Exp $"
// "$Id: Fl_Help_View.cxx,v 1.1.2.14 2001/11/24 04:12:56 easysw Exp $"
//
// Fl_Help_View widget routines.
//
@ -94,6 +94,7 @@ extern "C"
//
static void scrollbar_callback(Fl_Widget *s, void *);
static void hscrollbar_callback(Fl_Widget *s, void *);
//
@ -295,20 +296,33 @@ Fl_Help_View::draw()
Fl_Color tc, c; // Table/cell background color
// Draw the scrollbar and box first...
if (scrollbar_.visible())
{
draw_child(scrollbar_);
draw_box(b, x(), y(), w() - 17, h(), bgcolor_);
// Draw the scrollbar(s) and box first...
ww = w();
hh = h();
i = 0;
if (hscrollbar_.visible()) {
draw_child(hscrollbar_);
hh -= 17;
i ++;
}
else
draw_box(b, x(), y(), w(), h(), bgcolor_);
if (scrollbar_.visible()) {
draw_child(scrollbar_);
ww -= 17;
i ++;
}
if (i == 2) {
fl_color(FL_GRAY);
fl_rectf(x() + ww, y() + hh, 17, 17);
}
draw_box(b, x(), y(), ww, hh, bgcolor_);
if (!value_)
return;
// Clip the drawing to the inside of the box...
fl_push_clip(x() + 4, y() + 4, w() - 28, h() - 8);
fl_push_clip(x() + 4, y() + 4, ww - 8, hh - 8);
fl_color(textcolor_);
tc = c = bgcolor_;
@ -350,7 +364,7 @@ Fl_Help_View::draw()
hh = 0;
}
fl_draw(buf, xx + x(), yy + y());
fl_draw(buf, xx + x() - leftline_, yy + y());
xx += ww;
if ((size + 2) > hh)
@ -367,7 +381,7 @@ Fl_Help_View::draw()
*s = '\0';
s = buf;
fl_draw(buf, xx + x(), yy + y());
fl_draw(buf, xx + x() - leftline_, yy + y());
if (line < 31)
line ++;
@ -395,7 +409,7 @@ Fl_Help_View::draw()
*s = '\0';
s = buf;
fl_draw(buf, xx + x(), yy + y());
fl_draw(buf, xx + x() - leftline_, yy + y());
xx += (int)fl_width(buf);
}
@ -486,7 +500,7 @@ Fl_Help_View::draw()
if (strcasecmp(buf, "LI") == 0)
{
fl_font(FL_SYMBOL, size);
fl_draw("\267", xx - size + x(), yy + y());
fl_draw("\267", xx - size + x() - leftline_, yy + y());
}
pushfont(font, size);
@ -494,7 +508,7 @@ Fl_Help_View::draw()
if (c != bgcolor_)
{
fl_color(c);
fl_rectf(block->x + x() - 4,
fl_rectf(block->x + x() - 4 - leftline_,
block->y - topline_ + y() - size - 3,
block->w - block->x + 7, block->h + size - 5);
fl_color(textcolor_);
@ -523,14 +537,14 @@ Fl_Help_View::draw()
if (c != bgcolor_)
{
fl_color(c);
fl_rectf(block->x + x() - 4,
fl_rectf(block->x + x() - 4 - leftline_,
block->y - topline_ + y() - size - 3,
block->w - block->x + 7, block->h + size - 5);
fl_color(textcolor_);
}
if (block->border)
fl_rect(block->x + x() - 4,
fl_rect(block->x + x() - 4 - leftline_,
block->y - topline_ + y() - size - 3,
block->w - block->x + 7, block->h + size - 5);
}
@ -578,8 +592,8 @@ Fl_Help_View::draw()
get_attr(attrs, "WIDTH", wattr, sizeof(wattr));
get_attr(attrs, "HEIGHT", hattr, sizeof(hattr));
width = atoi(wattr);
height = atoi(hattr);
width = get_length(wattr);
height = get_length(hattr);
if (get_attr(attrs, "SRC", attr, sizeof(attr))) {
img = get_image(attr, width, height);
@ -609,7 +623,7 @@ Fl_Help_View::draw()
}
if (img)
img->draw(xx + x(),
img->draw(xx + x() - leftline_,
yy + y() - fl_height() + fl_descent() + 2);
xx += ww;
@ -624,7 +638,7 @@ Fl_Help_View::draw()
*s = '\0';
s = buf;
fl_draw(buf, xx + x(), yy + y());
fl_draw(buf, xx + x() - leftline_, yy + y());
if (line < 31)
line ++;
@ -724,7 +738,7 @@ Fl_Help_View::draw()
}
if (s > buf && !head)
fl_draw(buf, xx + x(), yy + y());
fl_draw(buf, xx + x() - leftline_, yy + y());
}
fl_pop_clip();
@ -739,6 +753,7 @@ 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 row; // Current table row (block number)
@ -766,8 +781,14 @@ Fl_Help_View::format()
columns[MAX_COLUMNS];
// Column widths
// Reset document width...
hsize_ = w() - 24;
done = 0;
while (!done)
{
// Reset state variables...
done = 1;
nblocks_ = 0;
nlinks_ = 0;
ntargets_ = 0;
@ -792,7 +813,7 @@ Fl_Help_View::format()
column = 0;
border = 0;
hh = 0;
block = add_block(value_, xx, yy, w() - 24, 0);
block = add_block(value_, xx, yy, hsize_, 0);
row = 0;
head = 0;
pre = 0;
@ -811,11 +832,17 @@ Fl_Help_View::format()
*s = '\0';
ww = (int)fl_width(buf);
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);
// 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)
{
@ -842,6 +869,8 @@ Fl_Help_View::format()
{
if (*ptr == '\n')
{
if (xx > hsize_) break;
if (link[0])
add_link(link, xx, yy - hh, ww, hh);
@ -858,6 +887,12 @@ Fl_Help_View::format()
ptr ++;
}
if (xx > hsize_) {
hsize_ = xx;
done = 0;
break;
}
needspace = 0;
}
else
@ -977,6 +1012,12 @@ Fl_Help_View::format()
format_table(&table_width, columns, start);
if ((xx + table_width) > hsize_) {
hsize_ = xx + table_width;
done = 0;
break;
}
column = 0;
}
@ -1021,7 +1062,7 @@ Fl_Help_View::format()
if (row)
block = add_block(start, xx, yy, block->w, 0);
else
block = add_block(start, xx, yy, w() - 24, 0);
block = add_block(start, xx, yy, hsize_, 0);
needspace = 0;
line = 0;
@ -1080,7 +1121,7 @@ Fl_Help_View::format()
if (row)
block = add_block(ptr, xx, yy, block->w, 0);
else
block = add_block(ptr, xx, yy, w() - 24, 0);
block = add_block(ptr, xx, yy, hsize_, 0);
needspace = 0;
hh = 0;
@ -1110,7 +1151,7 @@ Fl_Help_View::format()
yy = block->y + block->h - 4;
hh = 0;
block = add_block(start, xx, yy, w() - 24, 0);
block = add_block(start, xx, yy, hsize_, 0);
row = block - blocks_;
needspace = 0;
column = 0;
@ -1136,7 +1177,7 @@ Fl_Help_View::format()
cell->h = block->h;
yy = block->y + block->h - 4;
block = add_block(start, xx, yy, w() - 24, 0);
block = add_block(start, xx, yy, hsize_, 0);
needspace = 0;
row = 0;
line = 0;
@ -1219,8 +1260,8 @@ Fl_Help_View::format()
get_attr(attrs, "WIDTH", wattr, sizeof(wattr));
get_attr(attrs, "HEIGHT", hattr, sizeof(hattr));
width = atoi(wattr);
height = atoi(hattr);
width = get_length(wattr);
height = get_length(hattr);
if (get_attr(attrs, "SRC", attr, sizeof(attr))) {
img = get_image(attr, width, height);
@ -1230,6 +1271,12 @@ Fl_Help_View::format()
ww = width;
if (ww > hsize_) {
hsize_ = ww;
done = 0;
break;
}
if (needspace && xx > block->x)
ww += (int)fl_width(' ');
@ -1257,6 +1304,12 @@ Fl_Help_View::format()
if (link[0])
add_link(link, xx, yy - hh, ww, hh);
if (xx > hsize_) {
hsize_ = xx;
done = 0;
break;
}
line = do_align(block, line, xx, newalign, links);
xx = block->x;
yy += hh;
@ -1330,8 +1383,14 @@ Fl_Help_View::format()
*s = '\0';
ww = (int)fl_width(buf);
// printf("line = %d, xx = %d, ww = %d, block->x = %d, block->w = %d\n",
// line, xx, ww, block->x, block->w);
// printf("line = %d, xx = %d, ww = %d, block->x = %d, block->w = %d\n",
// line, xx, ww, block->x, block->w);
if (ww > hsize_) {
hsize_ = ww;
done = 0;
break;
}
if (needspace && xx > block->x)
ww += (int)fl_width(' ');
@ -1357,6 +1416,7 @@ Fl_Help_View::format()
block->end = ptr;
size_ = yy + hh;
}
if (ntargets_ > 1)
qsort(targets_, ntargets_, sizeof(Fl_Help_Target),
@ -1366,12 +1426,29 @@ Fl_Help_View::format()
qsort(blocks_, nblocks_, sizeof(Fl_Help_Block),
(compare_func_t)compare_blocks);
if (size_ < (h() - 8))
if (hsize_ > (w() - 24)) {
hscrollbar_.show();
if (size_ < (h() - 24)) {
scrollbar_.hide();
else
hscrollbar_.resize(x(), y() + h() - 17, w(), 17);
} else {
scrollbar_.show();
scrollbar_.resize(x() + w() - 17, y(), 17, h() - 17);
hscrollbar_.resize(x(), y() + h() - 17, w() - 17, 17);
}
} else {
hscrollbar_.hide();
if (size_ < (h() - 8)) scrollbar_.hide();
else {
scrollbar_.resize(x() + w() - 17, y(), 17, h());
scrollbar_.show();
}
}
topline(topline_);
leftline(leftline_);
}
@ -1617,12 +1694,7 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width
pushfont(font, size);
if (get_attr(attrs, "WIDTH", attr, sizeof(attr)) != NULL)
{
max_width = atoi(attr);
if (attr[strlen(attr) - 1] == '%')
max_width = max_width * w() / 100;
}
max_width = get_length(attr);
else
max_width = 0;
@ -1662,8 +1734,8 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width
get_attr(attrs, "WIDTH", wattr, sizeof(wattr));
get_attr(attrs, "HEIGHT", hattr, sizeof(hattr));
iwidth = atoi(wattr);
iheight = atoi(hattr);
iwidth = get_length(wattr);
iheight = get_length(hattr);
if (get_attr(attrs, "SRC", attr, sizeof(attr))) {
img = get_image(attr, iwidth, iheight);
@ -1748,12 +1820,7 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width
// Now that we have scanned the entire table, adjust the table and
// cell widths to fit on the screen...
if (get_attr(table + 6, "WIDTH", attr, sizeof(attr)))
{
if (attr[strlen(attr) - 1] == '%')
*table_width = atoi(attr) * w() / 100;
else
*table_width = atoi(attr);
}
*table_width = get_length(attr);
else
*table_width = 0;
@ -1774,29 +1841,32 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width
// Adjust the width if needed...
int scale_width = *table_width;
if (scale_width == 0 && width > w())
scale_width = width;
if (scale_width == 0) {
if (width > hsize_) scale_width = hsize_;
else scale_width = width;
}
if (width > scale_width)
{
// printf("width = %d, scale_width = %d\n", width, scale_width);
*table_width = 0;
for (column = 0; column < num_columns; column ++)
{
if (width > 0)
{
temp_width = scale_width * columns[column] / width;
if (temp_width < minwidths[column])
temp_width = minwidths[column];
for (column = 0; column < num_columns; column ++) {
scale_width -= minwidths[column];
width -= minwidths[column];
columns[column] -= minwidths[column];
}
else
temp_width = minwidths[column];
width -= columns[column];
scale_width -= temp_width;
columns[column] = temp_width;
(*table_width) += temp_width;
// printf("extra width = %d, scale_width = %d\n", width, scale_width);
for (column = 0; column < num_columns; column ++) {
if (width > 0) {
columns[column] = scale_width * columns[column] / width +
minwidths[column];
} else columns[column] = minwidths[column];
(*table_width) += columns[column];
}
}
else if (*table_width == 0)
@ -2014,6 +2084,23 @@ Fl_Help_View::get_image(const char *name, int W, int H) {
}
//
// '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] == '%') val = val * hsize_ / 100;
return val;
}
//
// 'Fl_Help_View::handle()' - Handle events in the widget.
//
@ -2034,7 +2121,7 @@ Fl_Help_View::handle(int event) // I - Event to handle
return (1);
case FL_MOVE :
xx = Fl::event_x() - x();
xx = Fl::event_x() - x() + leftline_;
yy = Fl::event_y() - y() + topline_;
break;
@ -2124,7 +2211,8 @@ Fl_Help_View::Fl_Help_View(int xx, // I - Left position
int hh, // I - Height in pixels
const char *l)
: Fl_Group(xx, yy, ww, hh, l),
scrollbar_(xx + ww - 17, yy, 17, hh)
scrollbar_(xx + ww - 17, yy, 17, hh - 17),
hscrollbar_(xx, yy + hh - 17, ww - 17, 17)
{
link_ = (Fl_Help_Func *)0;
@ -2148,6 +2236,7 @@ Fl_Help_View::Fl_Help_View(int xx, // I - Left position
textsize_ = 12;
topline_ = 0;
leftline_ = 0;
size_ = 0;
color(FL_WHITE);
@ -2159,6 +2248,11 @@ Fl_Help_View::Fl_Help_View(int xx, // I - Left position
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();
}
@ -2316,14 +2410,14 @@ Fl_Help_View::topline(int t) // I - Top line number
if (!value_)
return;
if (size_ < (h() - 8) || t < 0)
if (size_ < (h() - 24) || t < 0)
t = 0;
else if (t > size_)
t = size_;
topline_ = t;
scrollbar_.value(topline_, h(), 0, size_);
scrollbar_.value(topline_, h() - 24, 0, size_);
do_callback();
clear_changed();
@ -2332,6 +2426,29 @@ Fl_Help_View::topline(int t) // I - Top line number
}
//
// '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.
//
@ -2378,5 +2495,16 @@ scrollbar_callback(Fl_Widget *s, void *)
//
// End of "$Id: Fl_Help_View.cxx,v 1.1.2.13 2001/11/24 02:46:19 easysw Exp $".
// 'hscrollbar_callback()' - A callback for the horizontal scrollbar.
//
static void
hscrollbar_callback(Fl_Widget *s, void *)
{
((Fl_Help_View *)(s->parent()))->leftline(int(((Fl_Scrollbar*)s)->value()));
}
//
// End of "$Id: Fl_Help_View.cxx,v 1.1.2.14 2001/11/24 04:12:56 easysw Exp $".
//