From ba892d265222409f0887b9cb92923c501b48decd Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 21 May 2003 16:12:14 +0000 Subject: Add find() method to help widget and search box to help dialog. Default to blue for the selection color on OSX; otherwise links and other visual elements are not the correct color. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2993 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_Help_View.cxx | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 2 deletions(-) (limited to 'src/Fl_Help_View.cxx') diff --git a/src/Fl_Help_View.cxx b/src/Fl_Help_View.cxx index e9d338b63..58c177fcb 100644 --- a/src/Fl_Help_View.cxx +++ b/src/Fl_Help_View.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Help_View.cxx,v 1.1.2.46 2003/01/30 21:41:54 easysw Exp $" +// "$Id: Fl_Help_View.cxx,v 1.1.2.47 2003/05/21 16:12:14 easysw Exp $" // // Fl_Help_View widget routines. // @@ -766,6 +766,68 @@ Fl_Help_View::draw() } +// +// 'Fl_Help_View::find()' - Find the specified string... +// + +int // O - Matching position or -1 if not found +Fl_Help_View::find(const char *s, // I - String to find + int p) // I - Starting position +{ + int i, // Looping var + c; // Current character + Fl_Help_Block *b; // Current block + const char *bp, // Block matching pointer + *bs, // Start of current comparison + *sp; // Search string pointer + + + // Range check input... + if (!s) return -1; + + if (p < 0 || p >= (int)strlen(value_)) p = 0; + else if (p > 0) p ++; + + // Look for the string... + for (i = nblocks_, b = blocks_; i > 0; i --, b ++) { + if (b->end < (value_ + p)) + continue; + + if (b->start < (value_ + p)) bp = value_ + p; + else bp = b->start; + + for (sp = s, bs = bp; *sp && *bp && bp < b->end; bp ++) { + if (*bp == '<') { + // skip to end of element... + while (*bp && bp < b->end && *bp != '>') bp ++; + continue; + } else if (*bp == '&') { + // decode HTML entity... + if ((c = quote_char(bp + 1)) < 0) c = '&'; + else bp = strchr(bp + 1, ';') + 1; + } else c = *bp; + + if (tolower(*sp) == tolower(c)) sp ++; + else { + // No match, so reset to start of search... + sp = s; + bs ++; + bp = bs; + } + } + + if (!*sp) { + // Found a match! + topline(b->y - b->h); + return (b->end - value_); + } + } + + // No match! + return (-1); +} + + // // 'Fl_Help_View::format()' - Format the help text. // @@ -2731,5 +2793,5 @@ hscrollbar_callback(Fl_Widget *s, void *) // -// End of "$Id: Fl_Help_View.cxx,v 1.1.2.46 2003/01/30 21:41:54 easysw Exp $". +// End of "$Id: Fl_Help_View.cxx,v 1.1.2.47 2003/05/21 16:12:14 easysw Exp $". // -- cgit v1.2.3