summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabien Costantini <fabien@onepost.net>2009-01-14 17:59:49 +0000
committerFabien Costantini <fabien@onepost.net>2009-01-14 17:59:49 +0000
commit49ed3ac9081b8699b51799bd546e347937304a1b (patch)
tree0c5241599033f15f3477ad49a4270c898f27ea4c
parent4cac674b2572e128eaa240d9f0f92a0f23cdfe06 (diff)
STR#890 non-lazy fix: as suggested, replaced the one level color attribute saving by a better font style stack including the color in its font style elements.
Took this opportunity to remove the separated font stack (font and size) tables by an opaque and dedicated font stack object implementation. This permits i.e to change easily the stack size or even impl. (like a linked list impl.) without impacting the widget code. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6633 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--FL/Fl_Help_View.H75
-rw-r--r--src/Fl_Help_View.cxx45
2 files changed, 80 insertions, 40 deletions
diff --git a/FL/Fl_Help_View.H b/FL/Fl_Help_View.H
index a98e40ed0..aff5099c3 100644
--- a/FL/Fl_Help_View.H
+++ b/FL/Fl_Help_View.H
@@ -84,6 +84,59 @@ struct Fl_Help_Link
};
/** Fl_Help_Target structure */
+
+/*
+ * Fl_Help_View font stack opaque implementation
+ */
+
+/** Fl_Help_View font stack element definition */
+struct Fl_Help_Font_Style {
+ Fl_Font f; ///< Font
+ Fl_Fontsize s; ///< Font Size
+ Fl_Color c; ///< Font Color
+ void get(Fl_Font &afont, Fl_Fontsize &asize, Fl_Color &acolor) {afont=f; asize=s; acolor=c;} ///< Gets current font attributes
+ void set(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {f=afont; s=asize; c=acolor;} ///< Sets current font attributes
+ Fl_Help_Font_Style(Fl_Font afont, Fl_Fontsize asize, Fl_Color acolor) {set(afont, asize, acolor);}
+ Fl_Help_Font_Style(){} // For in table use
+};
+
+/** Fl_Help_View font stack definition */
+const size_t MAX_FL_HELP_FS_ELTS = 100;
+
+struct Fl_Help_Font_Stack {
+ /** font stack construction, initialize attributes.*/
+ Fl_Help_Font_Stack() {
+ nfonts_ = 0;
+ }
+
+ void init(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
+ nfonts_ = 0;
+ elts_[nfonts_].set(f, s, c);
+ fl_font(f, s);
+ fl_color(c);
+ }
+ /** Gets the top (current) elt on the stack */
+ void top(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { elts_[nfonts_].get(f, s, c); }
+ /** Pushes the font style triplet on the stack, also calls fl_font() & fl_color() adequately */
+ void push(Fl_Font f, Fl_Fontsize s, Fl_Color c) {
+ if (nfonts_ < MAX_FL_HELP_FS_ELTS-1) nfonts_ ++;
+ elts_[nfonts_].set(f, s, c);
+ fl_font(f, s); fl_color(c);
+ }
+ /** Pops from the stack the font style triplet and calls fl_font() & fl_color() adequately */
+ void pop(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {
+ top(f, s, c);
+ fl_font(f, s); fl_color(c);
+ if (nfonts_ > 0) nfonts_ --;
+ }
+ /** Gets the current count of font style elts in the stack */
+ size_t count() const {return nfonts_;} /// Gets the current number of fonts in the stack
+
+protected:
+ size_t nfonts_; ///< current number of fonts in stack
+ Fl_Help_Font_Style elts_[100]; ///< font eletments
+};
+
struct Fl_Help_Target
{
char name[32]; ///< Target name
@@ -107,15 +160,11 @@ class FL_EXPORT Fl_Help_View : public Fl_Group //// Help viewer widget
Fl_Font textfont_; ///< Default font for text
Fl_Fontsize textsize_; ///< Default font size
const char *value_; ///< HTML text value
-
+ Fl_Help_Font_Stack fstack_; ///< font stack management
int nblocks_, ///< Number of blocks/paragraphs
ablocks_; ///< Allocated blocks
Fl_Help_Block *blocks_; ///< Blocks
- int nfonts_; ///< Number of fonts in stack
- Fl_Font fonts_[100]; ///< Font stack
- Fl_Fontsize font_sizes_[100]; ///< Font Size stack
-
Fl_Help_Func *link_; ///< Link transform function
int nlinks_, ///< Number of links
@@ -150,6 +199,12 @@ class FL_EXPORT Fl_Help_View : public Fl_Group //// Help viewer widget
static Fl_Color hv_selection_color;
static Fl_Color hv_selection_text_color;
+
+ void initfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) { f = textfont_; s = textsize_; c = textcolor_; fstack_.init(f, s, c); }
+ void pushfont(Fl_Font f, Fl_Fontsize s) {fstack_.push(f, s, textcolor_);}
+ void pushfont(Fl_Font f, Fl_Fontsize s, Fl_Color c) {fstack_.push(f, s, c);}
+ void popfont(Fl_Font &f, Fl_Fontsize &s, Fl_Color &c) {fstack_.pop(f, s, c);}
+
Fl_Help_Block *add_block(const char *s, int xx, int yy, int ww, int hh, uchar border = 0);
void add_link(const char *n, int xx, int yy, int ww, int hh);
void add_target(const char *n, int yy);
@@ -166,16 +221,6 @@ class FL_EXPORT Fl_Help_View : public Fl_Group //// Help viewer widget
int get_length(const char *l);
int handle(int);
- void initfont(Fl_Font &f, Fl_Fontsize &s) { nfonts_ = 0;
- fl_font(f = fonts_[0] = textfont_,
- s = font_sizes_[0] = textsize_); }
- void pushfont(Fl_Font f, Fl_Fontsize s) { if (nfonts_ < 99) nfonts_ ++;
- fl_font(fonts_[nfonts_] = f,
- font_sizes_[nfonts_] = s); }
- void popfont(Fl_Font &f, Fl_Fontsize &s) { if (nfonts_ > 0) nfonts_ --;
- fl_font(f = fonts_[nfonts_],
- s = font_sizes_[nfonts_]); }
-
void hv_draw(const char *t, int x, int y);
char begin_selection();
char extend_selection();
diff --git a/src/Fl_Help_View.cxx b/src/Fl_Help_View.cxx
index f38e65820..6dcda0083 100644
--- a/src/Fl_Help_View.cxx
+++ b/src/Fl_Help_View.cxx
@@ -444,14 +444,14 @@ Fl_Help_View::draw()
int xx, yy, ww, hh; // Current positions and sizes
int line; // Current line
Fl_Font font;
- Fl_Fontsize fsize; // Current font and size
+ Fl_Fontsize fsize; // Current font and size
+ Fl_Color fcolor; // current font color
int head, pre, // Flags for text
needspace; // Do we need whitespace?
Fl_Boxtype b = box() ? box() : FL_DOWN_BOX;
// Box to draw...
int underline, // Underline text?
xtra_ww; // Extra width for underlined space between words
- Fl_Color prev_text_color=FL_RED; // Saved text color before font color modification
// Draw the scrollbar(s) and box first...
ww = w() ;
@@ -504,7 +504,7 @@ Fl_Help_View::draw()
needspace = 0;
underline = 0;
- initfont(font, fsize);
+ initfont(font, fsize, fcolor);
for (ptr = block->start, s = buf; ptr < block->end;)
{
@@ -720,8 +720,7 @@ Fl_Help_View::draw()
else if (strcasecmp(buf, "FONT") == 0)
{
if (get_attr(attrs, "COLOR", attr, sizeof(attr)) != NULL) {
- prev_text_color = textcolor_;
- fl_color( (textcolor_ = get_color(attr, textcolor_)) );
+ pushfont(font, fsize, (textcolor_ = get_color(attr, textcolor_)) );
}
if (get_attr(attrs, "FACE", attr, sizeof(attr)) != NULL) {
@@ -748,9 +747,7 @@ Fl_Help_View::draw()
}
else if (strcasecmp(buf, "/FONT") == 0)
{
- textcolor_ = prev_text_color;
- fl_color(textcolor_);
- popfont(font, fsize);
+ popfont(font, fsize, textcolor_);
}
else if (strcasecmp(buf, "U") == 0)
underline = 1;
@@ -825,10 +822,10 @@ Fl_Help_View::draw()
strcasecmp(buf, "/TT") == 0 ||
strcasecmp(buf, "/KBD") == 0 ||
strcasecmp(buf, "/VAR") == 0)
- popfont(font, fsize);
+ popfont(font, fsize, fcolor);
else if (strcasecmp(buf, "/PRE") == 0)
{
- popfont(font, fsize);
+ popfont(font, fsize, fcolor);
pre = 0;
}
else if (strcasecmp(buf, "IMG") == 0)
@@ -1063,7 +1060,8 @@ void Fl_Help_View::format() {
int line; // Current line in block
int links; // Links for current line
Fl_Font font;
- Fl_Fontsize fsize; // Current font and size
+ Fl_Fontsize fsize; // Current font and size
+ Fl_Color fcolor; // Current font color
unsigned char border; // Draw border?
int talign, // Current alignment
newalign, // New alignment
@@ -1105,7 +1103,7 @@ void Fl_Help_View::format() {
return;
// Setup for formatting...
- initfont(font, fsize);
+ initfont(font, fsize, fcolor);
line = 0;
links = 0;
@@ -1454,7 +1452,7 @@ void Fl_Help_View::format() {
else if (strcasecmp(buf, "/CENTER") == 0)
talign = LEFT;
- popfont(font, fsize);
+ popfont(font, fsize, fcolor);
//#warning FIXME this isspace & 255 test will probably not work on a utf8 stream... And we use it everywhere!
while (isspace((*ptr)&255))
@@ -1604,7 +1602,7 @@ void Fl_Help_View::format() {
strcasecmp(buf, "/TH") == 0) && row)
{
line = do_align(block, line, xx, newalign, links);
- popfont(font, fsize);
+ popfont(font, fsize, fcolor);
xx = margins.pop();
talign = LEFT;
}
@@ -1633,7 +1631,7 @@ void Fl_Help_View::format() {
pushfont(font, fsize);
}
else if (strcasecmp(buf, "/FONT") == 0)
- popfont(font, fsize);
+ popfont(font, fsize, fcolor);
else if (strcasecmp(buf, "B") == 0 ||
strcasecmp(buf, "STRONG") == 0)
pushfont(font |= FL_BOLD, fsize);
@@ -1655,7 +1653,7 @@ void Fl_Help_View::format() {
strcasecmp(buf, "/TT") == 0 ||
strcasecmp(buf, "/KBD") == 0 ||
strcasecmp(buf, "/VAR") == 0)
- popfont(font, fsize);
+ popfont(font, fsize, fcolor);
else if (strcasecmp(buf, "IMG") == 0)
{
Fl_Shared_Image *img = 0;
@@ -1877,8 +1875,8 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width
*start; // Start of element
int minwidths[MAX_COLUMNS]; // Minimum widths for each column
Fl_Font font;
- Fl_Fontsize fsize; // Current font and size
-
+ Fl_Fontsize fsize; // Current font and size
+ Fl_Color fcolor; // Currrent font color
// Clear widths...
*table_width = 0;
@@ -1893,8 +1891,7 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width
max_width = 0;
pre = 0;
needspace = 0;
- font = fonts_[nfonts_];
- fsize = font_sizes_[nfonts_];
+ fstack_.top(font, fsize, fcolor);
// Scan the table...
for (ptr = table, column = -1, width = 0, s = buf, incell = 0; *ptr;)
@@ -2014,7 +2011,7 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width
width = 0;
needspace = 0;
- popfont(font, fsize);
+ popfont(font, fsize, fcolor);
}
else if (strcasecmp(buf, "TR") == 0 || strcasecmp(buf, "/TR") == 0 ||
strcasecmp(buf, "/TABLE") == 0)
@@ -2104,7 +2101,7 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width
strcasecmp(buf, "/TH") == 0)
{
incell = 0;
- popfont(font, fsize);
+ popfont(font, fsize, fcolor);
}
else if (strcasecmp(buf, "B") == 0 ||
strcasecmp(buf, "STRONG") == 0)
@@ -2127,7 +2124,7 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width
strcasecmp(buf, "/TT") == 0 ||
strcasecmp(buf, "/KBD") == 0 ||
strcasecmp(buf, "/VAR") == 0)
- popfont(font, fsize);
+ popfont(font, fsize, fcolor);
else if (strcasecmp(buf, "IMG") == 0 && incell)
{
Fl_Shared_Image *img = 0;
@@ -2986,8 +2983,6 @@ Fl_Help_View::Fl_Help_View(int xx, // I - Left position
nblocks_ = 0;
blocks_ = (Fl_Help_Block *)0;
- nfonts_ = 0;
-
link_ = (Fl_Help_Func *)0;
alinks_ = 0;