Fix image handling in Fl_Help_View (STR #2163 and STR #2004).
src/Fl_Help_View.cxx:
This fix is the first step and compatible with FLTK 1.1 (keeping the ABI).
The next step should be to manage the loaded images in an own structure,
because we must know exactly, when to release() the images. The previous
version would release images too many times and could release shared
images that had been loaded by another part of the program (maybe even
another Fl_Help_View widget).
FL/Fl_Help_View.H:
Doxygen comments improved.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@6743 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
@ -96,6 +96,11 @@ static int quote_char(const char *);
@@ -96,6 +96,11 @@ static int quote_char(const char *);
staticvoidscrollbar_callback(Fl_Widget*s,void*);
staticvoidhscrollbar_callback(Fl_Widget*s,void*);
//
// global flag for image loading (see get_image).
//
staticcharinitial_load=0;
//
// Broken image...
@ -273,7 +278,7 @@ void Fl_Help_View::hv_draw(const char *t, int x, int y)
@@ -273,7 +278,7 @@ void Fl_Help_View::hv_draw(const char *t, int x, int y)
}
/** Add a text block to the list. */
/** Adds a text block to the list. */
Fl_Help_Block*// O - Pointer to new block
Fl_Help_View::add_block(constchar*s,// I - Pointer to start of block text
intxx,// I - X position of block
@ -314,7 +319,7 @@ Fl_Help_View::add_block(const char *s, // I - Pointer to start of block text
@@ -314,7 +319,7 @@ Fl_Help_View::add_block(const char *s, // I - Pointer to start of block text
}
/** Add a new link to the list. */
/** Adds a new link to the list. */
voidFl_Help_View::add_link(constchar*n,// I - Name of link
intxx,// I - X position of link
intyy,// I - Y position of link
@ -381,7 +386,7 @@ void Fl_Help_View::add_target(const char *n, // I - Name of target
@@ -381,7 +386,7 @@ void Fl_Help_View::add_target(const char *n, // I - Name of target
ntargets_++;
}
/** Compare two targets.*/
/** Compares two targets.*/
int// O - Result of comparison
Fl_Help_View::compare_targets(constFl_Help_Target*t0,// I - First target
constFl_Help_Target*t1)// I - Second target
@ -389,7 +394,7 @@ Fl_Help_View::compare_targets(const Fl_Help_Target *t0, // I - First target
@@ -389,7 +394,7 @@ Fl_Help_View::compare_targets(const Fl_Help_Target *t0, // I - First target
return(strcasecmp(t0->name,t1->name));
}
/** Compute the alignment for a line in a block.*/
/** Computes the alignment for a line in a block.*/
int// O - New line
Fl_Help_View::do_align(Fl_Help_Block*block,// I - Block to add to
intline,// I - Current line
@ -428,7 +433,7 @@ Fl_Help_View::do_align(Fl_Help_Block *block, // I - Block to add to
@@ -428,7 +433,7 @@ Fl_Help_View::do_align(Fl_Help_Block *block, // I - Block to add to
Fl_Help_View::get_align(constchar*p,// I - Pointer to start of attrs
inta)// I - Default alignment
@ -2424,7 +2424,7 @@ Fl_Help_View::get_align(const char *p, // I - Pointer to start of attrs
@@ -2424,7 +2424,7 @@ Fl_Help_View::get_align(const char *p, // I - Pointer to start of attrs
}
/** Get an attribute value from the string. */
/** Gets an attribute value from the string. */
constchar*// O - Pointer to buf or NULL
Fl_Help_View::get_attr(constchar*p,// I - Pointer to start of attributes
constchar*n,// I - Name of attribute
@ -2496,7 +2496,7 @@ Fl_Help_View::get_attr(const char *p, // I - Pointer to start of attributes
@@ -2496,7 +2496,7 @@ Fl_Help_View::get_attr(const char *p, // I - Pointer to start of attributes
}
/** Get an alignment attribute. */
/** Gets a color attribute. */
Fl_Color// O - Color value
Fl_Help_View::get_color(constchar*n,// I - Color name
Fl_Colorc)// I - Default color value
@ -2555,7 +2555,48 @@ Fl_Help_View::get_color(const char *n, // I - Color name
@@ -2555,7 +2555,48 @@ Fl_Help_View::get_color(const char *n, // I - Color name
Fl_Help_View::handle(intevent)// I - Event to handle
{
@ -3034,23 +3085,24 @@ Fl_Help_View::Fl_Help_View(int xx, // I - Left position
@@ -3034,23 +3085,24 @@ Fl_Help_View::Fl_Help_View(int xx, // I - Left position
Fl_Help_View::load(constchar*f)// I - Filename to load (may also have target)
/** This method loads the specified file or URL.*/
{
FILE*fp;// File to read from
longlen;// Length of file
@ -3060,6 +3112,7 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
@@ -3060,6 +3112,7 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
charerror[1024];// Error buffer
charnewname[1024];// New filename buffer
// printf("load(%s)\n",f); fflush(stdout);
if(strncmp(f,"ftp:",4)==0||
strncmp(f,"http:",5)==0||
@ -3083,6 +3136,8 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
@@ -3083,6 +3136,8 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
if(!localname)
return(0);
free_data();
strlcpy(filename_,newname,sizeof(filename_));
strlcpy(directory_,newname,sizeof(directory_));
@ -3106,6 +3161,7 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
@@ -3106,6 +3161,7 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
}
clear_selection();
free_data();
strlcpy(newname,f,sizeof(newname));
if((target=strrchr(newname,'#'))!=NULL)
@ -3129,12 +3185,6 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
@@ -3129,12 +3185,6 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
elseif(slash>directory_&&slash[-1]!='/')
*slash='\0';
if(value_!=NULL)
{
free((void*)value_);
value_=NULL;
}
if(strncmp(localname,"file:",5)==0)
localname+=5;// Adjust for local filename...
@ -3159,7 +3209,9 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
@@ -3159,7 +3209,9 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
value_=strdup(error);
}
initial_load=1;
format();
initial_load=0;
if(target)
topline(target);
@ -3170,7 +3222,7 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
@@ -3170,7 +3222,7 @@ Fl_Help_View::load(const char *f)// I - Filename to load (may also have target)
}
/** Resize the help widget. */
/** Resizes the help widget. */
void
Fl_Help_View::resize(intxx,// I - New left position
@ -3195,7 +3247,10 @@ Fl_Help_View::resize(int xx, // I - New left position
@@ -3195,7 +3247,10 @@ Fl_Help_View::resize(int xx, // I - New left position
}
/** Scroll the text to the indicated position, given a named destination */
/** Scrolls the text to the indicated position, given a named destination.
\param[in]ntargetname
*/
void
Fl_Help_View::topline(constchar*n)// I - Target name
{
@ -3216,21 +3271,26 @@ Fl_Help_View::topline(const char *n) // I - Target name
@@ -3216,21 +3271,26 @@ Fl_Help_View::topline(const char *n) // I - Target name
}
/** Scrolls the text to the indicated position, given a pixel line.