diff options
| -rw-r--r-- | CHANGES | 2 | ||||
| -rw-r--r-- | FL/Fl_Help_View.H | 1 | ||||
| -rw-r--r-- | src/Fl_Help_View.cxx | 126 |
3 files changed, 116 insertions, 13 deletions
@@ -4,6 +4,8 @@ CHANGES IN FLTK 1.1.8 STR #1457, STR #1458, STR #1460, STR #1481, STR #1578, STR #1639, STR #1645, STR #1644, STR #1792, STR #1793, STR #1742, STR #1777, STR #1794) + - Fl_Help_View did not release the images it used (STR + #1817) - Shared libraries would not build on 64-bit Linux systems with an existing non-PIC FLTK installation (STR #1791) diff --git a/FL/Fl_Help_View.H b/FL/Fl_Help_View.H index e2ac842db..5f4d9d3f9 100644 --- a/FL/Fl_Help_View.H +++ b/FL/Fl_Help_View.H @@ -156,6 +156,7 @@ class FL_EXPORT Fl_Help_View : public Fl_Group //// Help viewer widget void draw(); void format(); void format_table(int *table_width, int *columns, const char *table); + void free_data(); int get_align(const char *p, int a); const char *get_attr(const char *p, const char *n, char *buf, int bufsize); Fl_Color get_color(const char *n, Fl_Color c); diff --git a/src/Fl_Help_View.cxx b/src/Fl_Help_View.cxx index 44f2d9037..1e524edf1 100644 --- a/src/Fl_Help_View.cxx +++ b/src/Fl_Help_View.cxx @@ -36,6 +36,7 @@ // Fl_Help_View::draw() - Draw the Fl_Help_View widget. // Fl_Help_View::format() - Format the help text. // Fl_Help_View::format_table() - Format a table... +// Fl_Help_View::free_data() - Free memory used for the document. // Fl_Help_View::get_align() - Get an alignment attribute. // Fl_Help_View::get_attr() - Get an attribute value from the string. // Fl_Help_View::get_color() - Get an alignment attribute. @@ -888,9 +889,11 @@ Fl_Help_View::draw() hh = 0; } - if (img) + if (img) { img->draw(xx + x() - leftline_, yy + y() - fl_height() + fl_descent() + 2); + img->release(); + } xx += ww; if ((height + 2) > hh) @@ -2297,6 +2300,111 @@ Fl_Help_View::format_table(int *table_width, // O - Total table width // +// 'Fl_Help_View::free_data()' - Free memory used for the document. +// + +void +Fl_Help_View::free_data() { + // Releae all images... + if (value_) { + const char *ptr, // Pointer into block + *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 + + + for (ptr = value_; *ptr;) + { + if (*ptr == '<') + { + ptr ++; + + if (strncmp(ptr, "!--", 3) == 0) + { + // Comment... + ptr += 3; + if ((ptr = strstr(ptr, "-->")) != NULL) + { + ptr += 3; + continue; + } + else + break; + } + + s = buf; + + while (*ptr && *ptr != '>' && !isspace((*ptr)&255)) + if (s < (buf + sizeof(buf) - 1)) + *s++ = *ptr++; + else + ptr ++; + + *s = '\0'; + + attrs = ptr; + while (*ptr && *ptr != '>') + ptr ++; + + if (*ptr == '>') + ptr ++; + + if (strcasecmp(buf, "IMG") == 0) + { + Fl_Shared_Image *img; + int width; + int height; + + + 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))) { + // Release the image twice to free it from memory... + img = get_image(attr, width, height); + img->release(); + img->release(); + } + } + } + } + + free((void *)value_); + value_ = 0; + } + + // Free all of the arrays... + if (nblocks_) { + free(blocks_); + + ablocks_ = 0; + nblocks_ = 0; + blocks_ = 0; + } + + if (nlinks_) { + free(links_); + + alinks_ = 0; + nlinks_ = 0; + links_ = 0; + } + + if (ntargets_) { + free(targets_); + + atargets_ = 0; + ntargets_ = 0; + targets_ = 0; + } +} + +// // 'Fl_Help_View::get_align()' - Get an alignment attribute. // @@ -2949,14 +3057,8 @@ Fl_Help_View::Fl_Help_View(int xx, // I - Left position Fl_Help_View::~Fl_Help_View() { - if (nblocks_) - free(blocks_); - if (nlinks_) - free(links_); - if (ntargets_) - free(targets_); - if (value_) - free((void *)value_); + clear_selection(); + free_data(); } @@ -3167,18 +3269,16 @@ void Fl_Help_View::value(const char *v) // I - Text to view { clear_selection(); + free_data(); + set_changed(); if (!v) return; - if (value_ != NULL) - free((void *)value_); - value_ = strdup(v); format(); - set_changed(); topline(0); leftline(0); } |
