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
This commit is contained in:
Michael R Sweet 2003-05-21 16:12:14 +00:00
parent 2549a4ad62
commit ba892d2652
7 changed files with 111 additions and 21 deletions

View File

@ -1,5 +1,9 @@
CHANGES IN FLTK 1.1.4 CHANGES IN FLTK 1.1.4
- The Fl_Help_View widget now provides a find() method
to search for text within the page.
- The Fl_Help_Dialog widget now provides a search box
for entering text to search for.
- The default font encoding on OSX did not match the - The default font encoding on OSX did not match the
default on WIN32 or X11. default on WIN32 or X11.
- Menu items were not drawn using the font specified in - Menu items were not drawn using the font specified in

View File

@ -6,12 +6,14 @@
#include <FL/Fl_Double_Window.H> #include <FL/Fl_Double_Window.H>
#include <FL/Fl_Help_View.H> #include <FL/Fl_Help_View.H>
#include <FL/Fl_Button.H> #include <FL/Fl_Button.H>
#include <FL/Fl_Input.H>
class FL_EXPORT Fl_Help_Dialog { class FL_EXPORT Fl_Help_Dialog {
int index_; int index_;
int max_; int max_;
int line_[100]; int line_[100];
char file_[100][256]; char file_[100][256];
int find_pos_;
public: public:
Fl_Help_Dialog(); Fl_Help_Dialog();
private: private:
@ -33,6 +35,9 @@ private:
Fl_Button *larger_; Fl_Button *larger_;
inline void cb_larger__i(Fl_Button*, void*); inline void cb_larger__i(Fl_Button*, void*);
static void cb_larger_(Fl_Button*, void*); static void cb_larger_(Fl_Button*, void*);
Fl_Input *find_;
inline void cb_find__i(Fl_Input*, void*);
static void cb_find_(Fl_Input*, void*);
public: public:
~Fl_Help_Dialog(); ~Fl_Help_Dialog();
int h(); int h();

View File

@ -1,5 +1,5 @@
// //
// "$Id: Fl_Help_View.H,v 1.1.2.11 2003/01/30 21:39:13 easysw Exp $" // "$Id: Fl_Help_View.H,v 1.1.2.12 2003/05/21 16:12:14 easysw Exp $"
// //
// Help Viewer widget definitions. // Help Viewer widget definitions.
// //
@ -164,6 +164,7 @@ class FL_EXPORT Fl_Help_View : public Fl_Group //// Help viewer widget
else return ((const char *)0); } else return ((const char *)0); }
const char *filename() const { if (filename_[0]) return (filename_); const char *filename() const { if (filename_[0]) return (filename_);
else return ((const char *)0); } else return ((const char *)0); }
int find(const char *s, int p = 0);
void link(Fl_Help_Func *fn) { link_ = fn; } void link(Fl_Help_Func *fn) { link_ = fn; }
int load(const char *f); int load(const char *f);
void resize(int,int,int,int); void resize(int,int,int,int);
@ -187,5 +188,5 @@ class FL_EXPORT Fl_Help_View : public Fl_Group //// Help viewer widget
#endif // !Fl_Help_View_H #endif // !Fl_Help_View_H
// //
// End of "$Id: Fl_Help_View.H,v 1.1.2.11 2003/01/30 21:39:13 easysw Exp $". // End of "$Id: Fl_Help_View.H,v 1.1.2.12 2003/05/21 16:12:14 easysw Exp $".
// //

View File

@ -106,6 +106,13 @@ void Fl_Help_Dialog::cb_larger_(Fl_Button* o, void* v) {
((Fl_Help_Dialog*)(o->parent()->user_data()))->cb_larger__i(o,v); ((Fl_Help_Dialog*)(o->parent()->user_data()))->cb_larger__i(o,v);
} }
inline void Fl_Help_Dialog::cb_find__i(Fl_Input*, void*) {
find_pos_ = view_->find(find_->value(), find_pos_);
}
void Fl_Help_Dialog::cb_find_(Fl_Input* o, void* v) {
((Fl_Help_Dialog*)(o->parent()->user_data()))->cb_find__i(o,v);
}
Fl_Help_Dialog::Fl_Help_Dialog() { Fl_Help_Dialog::Fl_Help_Dialog() {
Fl_Double_Window* w; Fl_Double_Window* w;
{ Fl_Double_Window* o = window_ = new Fl_Double_Window(530, 385, "Help Dialog"); { Fl_Double_Window* o = window_ = new Fl_Double_Window(530, 385, "Help Dialog");
@ -129,37 +136,42 @@ Fl_Help_Dialog::Fl_Help_Dialog() {
o->callback((Fl_Callback*)cb_Close); o->callback((Fl_Callback*)cb_Close);
o->label(fl_close); o->label(fl_close);
} }
{ Fl_Button* o = back_ = new Fl_Button(365, 350, 25, 25, "@<-"); { Fl_Button* o = back_ = new Fl_Button(355, 350, 25, 25, "@<-");
o->tooltip("Show the previous help page."); o->tooltip("Show the previous help page.");
o->shortcut(0xff51); o->shortcut(0xff51);
o->labelcolor(2); o->labelcolor(2);
o->callback((Fl_Callback*)cb_back_); o->callback((Fl_Callback*)cb_back_);
} }
{ Fl_Button* o = forward_ = new Fl_Button(395, 350, 25, 25, "@->"); { Fl_Button* o = forward_ = new Fl_Button(390, 350, 25, 25, "@->");
o->tooltip("Show the next help page."); o->tooltip("Show the next help page.");
o->shortcut(0xff53); o->shortcut(0xff53);
o->labelcolor(2); o->labelcolor(2);
o->callback((Fl_Callback*)cb_forward_); o->callback((Fl_Callback*)cb_forward_);
} }
{ Fl_Button* o = smaller_ = new Fl_Button(305, 350, 25, 25, "F"); { Fl_Button* o = smaller_ = new Fl_Button(285, 350, 25, 25, "F");
o->tooltip("Make the help text smaller."); o->tooltip("Make the help text smaller.");
o->labelfont(1); o->labelfont(1);
o->labelsize(10); o->labelsize(10);
o->callback((Fl_Callback*)cb_smaller_); o->callback((Fl_Callback*)cb_smaller_);
} }
{ Fl_Button* o = larger_ = new Fl_Button(335, 350, 25, 25, "F"); { Fl_Button* o = larger_ = new Fl_Button(320, 350, 25, 25, "F");
o->tooltip("Make the help text larger."); o->tooltip("Make the help text larger.");
o->labelfont(1); o->labelfont(1);
o->labelsize(16); o->labelsize(16);
o->callback((Fl_Callback*)cb_larger_); o->callback((Fl_Callback*)cb_larger_);
} }
{ Fl_Input* o = find_ = new Fl_Input(10, 350, 265, 25);
o->callback((Fl_Callback*)cb_find_);
o->when(FL_WHEN_ENTER_KEY_ALWAYS);
}
o->end(); o->end();
} }
back_->deactivate(); back_->deactivate();
forward_->deactivate(); forward_->deactivate();
index_ = -1; index_ = -1;
max_ = 0; max_ = 0;
find_pos_ = 0;
fl_register_images(); fl_register_images();
} }

View File

@ -12,11 +12,12 @@ class FL_EXPORT Fl_Help_Dialog {open
decl {int max_;} {} decl {int max_;} {}
decl {int line_[100];} {} decl {int line_[100];} {}
decl {char file_[100][256];} {} decl {char file_[100][256];} {}
decl {int find_pos_;} {}
Function {Fl_Help_Dialog()} {open Function {Fl_Help_Dialog()} {open
} { } {
Fl_Window window_ { Fl_Window window_ {
label {Help Dialog} open label {Help Dialog} open
private xywh {470 380 530 385} type Double resizable visible private xywh {398 65 530 385} type Double resizable visible
} { } {
Fl_Group view_ { Fl_Group view_ {
callback {if (view_->changed()) callback {if (view_->changed())
@ -47,7 +48,7 @@ else if (view_->filename())
{ {
strlcpy(file_[index_], view_->filename(), sizeof(file_[0])); strlcpy(file_[index_], view_->filename(), sizeof(file_[0]));
line_[index_] = view_->topline(); line_[index_] = view_->topline();
}} open selected }} open
private xywh {10 10 510 330} box DOWN_BOX selection_color 15 resizable private xywh {10 10 510 330} box DOWN_BOX selection_color 15 resizable
code0 {\#include <FL/Fl_Help_View.H>} code0 {\#include <FL/Fl_Help_View.H>}
class Fl_Help_View class Fl_Help_View
@ -72,7 +73,7 @@ if (strcmp(view_->filename(), file_[index_]) != 0)
view_->load(file_[index_]); view_->load(file_[index_]);
view_->topline(line_[index_]);} view_->topline(line_[index_]);}
private tooltip {Show the previous help page.} xywh {365 350 25 25} shortcut 0xff51 labelcolor 2 private tooltip {Show the previous help page.} xywh {355 350 25 25} shortcut 0xff51 labelcolor 2
} }
Fl_Button forward_ { Fl_Button forward_ {
label {@->} label {@->}
@ -88,7 +89,7 @@ if (strcmp(view_->filename(), file_[index_]) != 0)
view_->load(file_[index_]); view_->load(file_[index_]);
view_->topline(line_[index_]);} view_->topline(line_[index_]);}
private tooltip {Show the next help page.} xywh {395 350 25 25} shortcut 0xff53 labelcolor 2 private tooltip {Show the next help page.} xywh {390 350 25 25} shortcut 0xff53 labelcolor 2
} }
Fl_Button smaller_ { Fl_Button smaller_ {
label F label F
@ -98,7 +99,7 @@ view_->topline(line_[index_]);}
if (view_->textsize() <= 8) if (view_->textsize() <= 8)
smaller_->deactivate(); smaller_->deactivate();
larger_->activate();} larger_->activate();}
private tooltip {Make the help text smaller.} xywh {305 350 25 25} labelfont 1 labelsize 10 private tooltip {Make the help text smaller.} xywh {285 350 25 25} labelfont 1 labelsize 10
} }
Fl_Button larger_ { Fl_Button larger_ {
label F label F
@ -108,14 +109,19 @@ larger_->activate();}
if (view_->textsize() >= 18) if (view_->textsize() >= 18)
larger_->deactivate(); larger_->deactivate();
smaller_->activate();} smaller_->activate();}
private tooltip {Make the help text larger.} xywh {335 350 25 25} labelfont 1 labelsize 16 private tooltip {Make the help text larger.} xywh {320 350 25 25} labelfont 1 labelsize 16
}
Fl_Input find_ {
callback {find_pos_ = view_->find(find_->value(), find_pos_);} selected
private xywh {10 350 265 25} when 10
} }
} }
code {back_->deactivate(); code {back_->deactivate();
forward_->deactivate(); forward_->deactivate();
index_ = -1; index_ = -1;
max_ = 0; max_ = 0;
find_pos_ = 0;
fl_register_images();} {} fl_register_images();} {}
} }

View File

@ -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. // 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. // '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 $".
// //

View File

@ -1,5 +1,5 @@
// //
// "$Id: Fl_get_system_colors.cxx,v 1.6.2.7.2.19 2003/05/18 22:12:21 easysw Exp $" // "$Id: Fl_get_system_colors.cxx,v 1.6.2.7.2.20 2003/05/21 16:12:14 easysw Exp $"
// //
// System color support for the Fast Light Tool Kit (FLTK). // System color support for the Fast Light Tool Kit (FLTK).
// //
@ -150,7 +150,7 @@ void Fl::get_system_colors()
foreground(0, 0, 0); foreground(0, 0, 0);
background(0xd8, 0xd8, 0xd8); background(0xd8, 0xd8, 0xd8);
background2(0xff, 0xff, 0xff); background2(0xff, 0xff, 0xff);
set_selection_color(0x80, 0x80, 0x80); set_selection_color(0x00, 0x00, 0x80);
} }
#else #else
@ -320,5 +320,5 @@ int Fl::reload_scheme() {
// //
// End of "$Id: Fl_get_system_colors.cxx,v 1.6.2.7.2.19 2003/05/18 22:12:21 easysw Exp $". // End of "$Id: Fl_get_system_colors.cxx,v 1.6.2.7.2.20 2003/05/21 16:12:14 easysw Exp $".
// //