From d3acd6c475de7fb811c4bde93ca735e3526ad82f Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Sat, 3 Nov 2001 05:11:34 +0000 Subject: [PATCH] Add Fl::visible_focus() method. Add optional "draw_symbols" argument to fl_draw and fl_measure functions. Fl_Repeat_Button didn't handle keyboard focus properly. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1678 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 7 +++++ FL/Fl.H | 9 ++++--- FL/Fl_Widget.H | 6 ++--- FL/fl_draw.H | 11 ++++---- src/Fl.cxx | 6 +++-- src/Fl_Browser.cxx | 6 ++--- src/Fl_File_Browser.cxx | 10 +++---- src/Fl_Repeat_Button.cxx | 5 ++-- src/Fl_Widget.cxx | 24 ++++++++++++++--- src/fl_draw.cxx | 58 +++++++++++++++++++++------------------- 10 files changed, 89 insertions(+), 53 deletions(-) diff --git a/CHANGES b/CHANGES index 0eaeca576..321188ee0 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,13 @@ CHANGES IN FLTK 1.1.0 contains a number. - The Fl_Browser::make_visible() method now range checks the input. + - Updated the fl_draw() and fl_measure() methods to + accept an optional draw_symbols argument, which + controls whether symbols are drawn in the text. + - Added new Fl::visible_focus() methods to control + whether the focus box is drawn. + - The focus box is now drawn using the contrast color. + - Fl_Repeat_Button didn't accept keyboard focus. CHANGES IN FLTK 1.1.0b5 diff --git a/FL/Fl.H b/FL/Fl.H index 72e61c353..7abf3ae9e 100644 --- a/FL/Fl.H +++ b/FL/Fl.H @@ -1,5 +1,5 @@ // -// "$Id: Fl.H,v 1.8.2.11.2.2 2001/08/06 03:17:43 easysw Exp $" +// "$Id: Fl.H,v 1.8.2.11.2.3 2001/11/03 05:11:33 easysw Exp $" // // Main header file for the Fast Light Tool Kit (FLTK). // @@ -61,7 +61,7 @@ public: // should be private! static FL_EXPORT Fl_Window* modal_; static FL_EXPORT Fl_Window* grab_; static FL_EXPORT int compose_state; - + static FL_EXPORT int visible_focus_; static void damage(int x) {damage_ = x;} static FL_EXPORT void (*idle)(); @@ -212,10 +212,13 @@ public: static FL_EXPORT void grab(Fl_Window&w) {grab(&w);} static FL_EXPORT void release() {grab(0);} + // Visible focus methods... + static void visible_focus(int v) { visible_focus_ = v; } + static int visible_focus() { return visible_focus_; } }; #endif // -// End of "$Id: Fl.H,v 1.8.2.11.2.2 2001/08/06 03:17:43 easysw Exp $". +// End of "$Id: Fl.H,v 1.8.2.11.2.3 2001/11/03 05:11:33 easysw Exp $". // diff --git a/FL/Fl_Widget.H b/FL/Fl_Widget.H index 6281d133c..795b72bde 100644 --- a/FL/Fl_Widget.H +++ b/FL/Fl_Widget.H @@ -1,5 +1,5 @@ // -// "$Id: Fl_Widget.H,v 1.6.2.4.2.9 2001/10/29 03:44:31 easysw Exp $" +// "$Id: Fl_Widget.H,v 1.6.2.4.2.10 2001/11/03 05:11:34 easysw Exp $" // // Widget header file for the Fast Light Tool Kit (FLTK). // @@ -90,7 +90,7 @@ protected: FL_EXPORT void draw_box() const; FL_EXPORT void draw_box(Fl_Boxtype, Fl_Color) const; FL_EXPORT void draw_box(Fl_Boxtype, int,int,int,int, Fl_Color) const; - FL_EXPORT void draw_focus() {draw_focus(box(),x(),y(),w(),h());} + void draw_focus() {draw_focus(box(),x(),y(),w(),h());} FL_EXPORT void draw_focus(Fl_Boxtype, int,int,int,int) const; FL_EXPORT void draw_label() const; FL_EXPORT void draw_label(int, int, int, int) const; @@ -207,5 +207,5 @@ public: #endif // -// End of "$Id: Fl_Widget.H,v 1.6.2.4.2.9 2001/10/29 03:44:31 easysw Exp $". +// End of "$Id: Fl_Widget.H,v 1.6.2.4.2.10 2001/11/03 05:11:34 easysw Exp $". // diff --git a/FL/fl_draw.H b/FL/fl_draw.H index e33ed8a39..3f21d9d9f 100644 --- a/FL/fl_draw.H +++ b/FL/fl_draw.H @@ -1,5 +1,5 @@ // -// "$Id: fl_draw.H,v 1.9.2.6.2.2 2001/08/05 23:58:54 easysw Exp $" +// "$Id: fl_draw.H,v 1.9.2.6.2.3 2001/11/03 05:11:34 easysw Exp $" // // Portable drawing function header file for the Fast Light Tool Kit (FLTK). // @@ -151,11 +151,12 @@ FL_EXPORT double fl_width(uchar); // draw using current font: FL_EXPORT void fl_draw(const char*, int x, int y); FL_EXPORT void fl_draw(const char*, int n, int x, int y); -FL_EXPORT void fl_measure(const char*, int& x, int& y); -FL_EXPORT void fl_draw(const char*, int,int,int,int, Fl_Align, Fl_Image* img=0); +FL_EXPORT void fl_measure(const char*, int& x, int& y, int draw_symbols = 1); +FL_EXPORT void fl_draw(const char*, int,int,int,int, Fl_Align, Fl_Image* img=0, + int draw_symbols = 1); FL_EXPORT void fl_draw(const char*, int,int,int,int, Fl_Align, void (*callthis)(const char *, int n, int x, int y), - Fl_Image* img=0); + Fl_Image* img=0, int draw_symbols = 1); // boxtypes: FL_EXPORT void fl_frame(const char* s, int x, int y, int w, int h); @@ -191,5 +192,5 @@ FL_EXPORT int fl_add_symbol(const char* name, void (*drawit)(Fl_Color), int scal #endif // -// End of "$Id: fl_draw.H,v 1.9.2.6.2.2 2001/08/05 23:58:54 easysw Exp $". +// End of "$Id: fl_draw.H,v 1.9.2.6.2.3 2001/11/03 05:11:34 easysw Exp $". // diff --git a/src/Fl.cxx b/src/Fl.cxx index 56ede9e44..d9b56e11a 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl.cxx,v 1.24.2.41.2.4 2001/10/18 00:24:19 easysw Exp $" +// "$Id: Fl.cxx,v 1.24.2.41.2.5 2001/11/03 05:11:34 easysw Exp $" // // Main event handling code for the Fast Light Tool Kit (FLTK). // @@ -53,6 +53,8 @@ int Fl::damage_, Fl::e_keysym; char *Fl::e_text = (char *)""; int Fl::e_length; +int Fl::visible_focus_ = 1; + // // 'Fl:event_inside()' - Return whether or not the mouse event is inside @@ -790,5 +792,5 @@ void Fl_Window::flush() { } // -// End of "$Id: Fl.cxx,v 1.24.2.41.2.4 2001/10/18 00:24:19 easysw Exp $". +// End of "$Id: Fl.cxx,v 1.24.2.41.2.5 2001/11/03 05:11:34 easysw Exp $". // diff --git a/src/Fl_Browser.cxx b/src/Fl_Browser.cxx index 78a7d716f..8d943f794 100644 --- a/src/Fl_Browser.cxx +++ b/src/Fl_Browser.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Browser.cxx,v 1.9.2.12.2.1 2001/10/29 03:44:32 easysw Exp $" +// "$Id: Fl_Browser.cxx,v 1.9.2.12.2.2 2001/11/03 05:11:34 easysw Exp $" // // Browser widget for the Fast Light Tool Kit (FLTK). // @@ -373,7 +373,7 @@ void Fl_Browser::item_draw(void* v, int x, int y, int w, int h) const { lcol = fl_contrast(lcol, selection_color()); if (!active_r()) lcol = fl_inactive(lcol); fl_color(lcol); - fl_draw(str, x+3, y, w1-6, h, e ? Fl_Align(align|FL_ALIGN_CLIP) : align); + fl_draw(str, x+3, y, w1-6, h, e ? Fl_Align(align|FL_ALIGN_CLIP) : align, 0, 0); if (!e) break; // no more fields... *e = column_char(); // put the seperator back x += w1; @@ -493,5 +493,5 @@ int Fl_Browser::value() const { } // -// End of "$Id: Fl_Browser.cxx,v 1.9.2.12.2.1 2001/10/29 03:44:32 easysw Exp $". +// End of "$Id: Fl_Browser.cxx,v 1.9.2.12.2.2 2001/11/03 05:11:34 easysw Exp $". // diff --git a/src/Fl_File_Browser.cxx b/src/Fl_File_Browser.cxx index 882d10360..f7ada7dae 100644 --- a/src/Fl_File_Browser.cxx +++ b/src/Fl_File_Browser.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_File_Browser.cxx,v 1.1.2.3 2001/10/29 21:59:14 easysw Exp $" +// "$Id: Fl_File_Browser.cxx,v 1.1.2.4 2001/11/03 05:11:34 easysw Exp $" // // Fl_File_Browser routines. // @@ -325,7 +325,7 @@ Fl_File_Browser::item_draw(void *p, // I - List item data *ptr = '\0'; fl_draw(fragment, x + width, y, w - width, fl_height(), - (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP)); + (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP), 0, 0); // Point back to the start of the fragment... ptr = fragment; @@ -339,7 +339,7 @@ Fl_File_Browser::item_draw(void *p, // I - List item data *ptr = '\0'; fl_draw(fragment, x + width, y, w - width, fl_height(), - (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP)); + (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP), 0, 0); // Advance to the next column... column ++; @@ -362,7 +362,7 @@ Fl_File_Browser::item_draw(void *p, // I - List item data *ptr = '\0'; fl_draw(fragment, x + width, y, w - width, fl_height(), - (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP)); + (Fl_Align)(FL_ALIGN_LEFT | FL_ALIGN_CLIP), 0, 0); } } @@ -566,5 +566,5 @@ Fl_File_Browser::filter(const char *pattern) // I - Pattern string // -// End of "$Id: Fl_File_Browser.cxx,v 1.1.2.3 2001/10/29 21:59:14 easysw Exp $". +// End of "$Id: Fl_File_Browser.cxx,v 1.1.2.4 2001/11/03 05:11:34 easysw Exp $". // diff --git a/src/Fl_Repeat_Button.cxx b/src/Fl_Repeat_Button.cxx index dbe60f473..88e4f44a9 100644 --- a/src/Fl_Repeat_Button.cxx +++ b/src/Fl_Repeat_Button.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Repeat_Button.cxx,v 1.4.2.4 2001/01/22 15:13:40 easysw Exp $" +// "$Id: Fl_Repeat_Button.cxx,v 1.4.2.4.2.1 2001/11/03 05:11:34 easysw Exp $" // // Repeat button widget for the Fast Light Tool Kit (FLTK). // @@ -44,6 +44,7 @@ int Fl_Repeat_Button::handle(int event) { newval = 0; goto J1; case FL_PUSH: case FL_DRAG: + take_focus(); newval = Fl::event_inside(this); J1: if (value(newval)) { @@ -61,5 +62,5 @@ int Fl_Repeat_Button::handle(int event) { } // -// End of "$Id: Fl_Repeat_Button.cxx,v 1.4.2.4 2001/01/22 15:13:40 easysw Exp $". +// End of "$Id: Fl_Repeat_Button.cxx,v 1.4.2.4.2.1 2001/11/03 05:11:34 easysw Exp $". // diff --git a/src/Fl_Widget.cxx b/src/Fl_Widget.cxx index ba29643e9..18f34b52f 100644 --- a/src/Fl_Widget.cxx +++ b/src/Fl_Widget.cxx @@ -1,5 +1,5 @@ // -// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.5 2001/08/06 03:17:43 easysw Exp $" +// "$Id: Fl_Widget.cxx,v 1.5.2.4.2.6 2001/11/03 05:11:34 easysw Exp $" // // Base widget class for the Fast Light Tool Kit (FLTK). // @@ -138,6 +138,7 @@ Fl_Widget::~Fl_Widget() { // draw a focus box for the widget... void Fl_Widget::draw_focus(Fl_Boxtype B, int X, int Y, int W, int H) const { + if (!Fl::visible_focus()) return; switch (B) { case FL_DOWN_BOX: case FL_DOWN_FRAME: @@ -149,11 +150,28 @@ Fl_Widget::draw_focus(Fl_Boxtype B, int X, int Y, int W, int H) const { break; } - fl_color(FL_BLACK); + fl_color(fl_contrast(FL_BLACK, color())); + +#ifdef WIN32 + // Windows 95/98/ME do not implement the dotted line style, so draw + // every other pixel around the focus area... + int i, xx, yy; + + X += Fl::box_dx(B); + Y += Fl::box_dy(B); + W -= Fl::box_dw(B) + 2; + H -= Fl::box_dh(B) + 2; + + for (xx = 0, i = 1; xx < W; xx ++, i ++) if (i & 1) fl_point(X + xx, Y); + for (yy = 0; yy < H; yy ++, i ++) if (i & 1) fl_point(X + W, Y + yy); + for (xx = W; xx > 0; xx --, i ++) if (i & 1) fl_point(X + xx, Y + H); + for (yy = H; yy > 0; yy --, i ++) if (i & 1) fl_point(X, Y + yy); +#else fl_line_style(FL_DOT); fl_rect(X + Fl::box_dx(B), Y + Fl::box_dy(B), W - Fl::box_dw(B) - 1, H - Fl::box_dh(B) - 1); fl_line_style(FL_SOLID); +#endif // WIN32 } @@ -231,5 +249,5 @@ int Fl_Widget::contains(const Fl_Widget *o) const { } // -// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.5 2001/08/06 03:17:43 easysw Exp $". +// End of "$Id: Fl_Widget.cxx,v 1.5.2.4.2.6 2001/11/03 05:11:34 easysw Exp $". // diff --git a/src/fl_draw.cxx b/src/fl_draw.cxx index 14eee12f1..2334941a5 100644 --- a/src/fl_draw.cxx +++ b/src/fl_draw.cxx @@ -1,5 +1,5 @@ // -// "$Id: fl_draw.cxx,v 1.6.2.4.2.5 2001/10/16 20:25:25 easysw Exp $" +// "$Id: fl_draw.cxx,v 1.6.2.4.2.6 2001/11/03 05:11:34 easysw Exp $" // // Label drawing code for the Fast Light Tool Kit (FLTK). // @@ -51,8 +51,8 @@ static char* underline_at; // Sets width to the width of the string in the current font. static const char* -expand(const char* from, char* buf, double maxw, int& n, double &width, int wrap) { - +expand(const char* from, char* buf, double maxw, int& n, double &width, + int wrap, int draw_symbols) { char* o = buf; char* e = buf+(MAXBUF-4); underline_at = 0; @@ -95,7 +95,7 @@ expand(const char* from, char* buf, double maxw, int& n, double &width, int wrap } else if (c == 0xA0) { // non-breaking space *o++ = ' '; } else if (c == '@') { // Symbol??? - if (p[1] && p[1] != '@') break; + if (p[1] && p[1] != '@' && draw_symbols) break; *o++ = c; if (p[1]) p++; } else { @@ -114,7 +114,7 @@ void fl_draw( int x, int y, int w, int h, // bounding box Fl_Align align, void (*callthis)(const char*,int,int,int), - Fl_Image* img) { + Fl_Image* img, int draw_symbols) { const char* p; const char* e; char buf[MAXBUF]; @@ -132,29 +132,32 @@ void fl_draw( symbol[1][0] = '\0'; symwidth[1] = 0; - if (str && str[0] == '@' && str[1] && str[1] != '@') { - // Start with a symbol... - for (symptr = symbol[0]; - *str && !isspace(*str) && symptr < (symbol[0] + sizeof(symbol[0]) - 1); - *symptr++ = *str++); - *symptr = '\0'; - if (isspace(*str)) str++; - symwidth[0] = min(w,h); - } + if (draw_symbols) { + if (str && str[0] == '@' && str[1] && str[1] != '@') { + // Start with a symbol... + for (symptr = symbol[0]; + *str && !isspace(*str) && symptr < (symbol[0] + sizeof(symbol[0]) - 1); + *symptr++ = *str++); + *symptr = '\0'; + if (isspace(*str)) str++; + symwidth[0] = min(w,h); + } - if (str && (p = strrchr(str, '@')) != NULL && p > (str + 1)) { - strncpy(symbol[1], p, sizeof(symbol[1]) - 1); - symbol[1][sizeof(symbol[1]) - 1] = '\0'; - symwidth[1] = min(w,h); + if (str && (p = strrchr(str, '@')) != NULL && p > (str + 1)) { + strncpy(symbol[1], p, sizeof(symbol[1]) - 1); + symbol[1][sizeof(symbol[1]) - 1] = '\0'; + symwidth[1] = min(w,h); + } } symtotal = symwidth[0] + symwidth[1]; if (str) { for (p = str, lines=0; p;) { - e = expand(p, buf, w - symtotal, buflen, width, align&FL_ALIGN_WRAP); + e = expand(p, buf, w - symtotal, buflen, width, align&FL_ALIGN_WRAP, + draw_symbols); lines++; - if (!*e || *e == '@') break; + if (!*e || (*e == '@' && draw_symbols)) break; p = e; } } else lines = 0; @@ -195,7 +198,7 @@ void fl_draw( int desc = fl_descent(); for (p=str; ; ypos += height) { if (lines>1) e = expand(p, buf, w - symtotal, buflen, width, - align&FL_ALIGN_WRAP); + align&FL_ALIGN_WRAP, draw_symbols); else e = ""; if (width > symoffset) symoffset = (int)(width + 0.5); @@ -257,15 +260,16 @@ void fl_draw( const char* str, // the (multi-line) string int x, int y, int w, int h, // bounding box Fl_Align align, - Fl_Image* img) { + Fl_Image* img, + int draw_symbols) { if ((!str || !*str) && !img) return; if (w && h && !fl_not_clipped(x, y, w, h)) return; if (align & FL_ALIGN_CLIP) fl_clip(x, y, w, h); - fl_draw(str, x, y, w, h, align, fl_draw, img); + fl_draw(str, x, y, w, h, align, fl_draw, img, draw_symbols); if (align & FL_ALIGN_CLIP) fl_pop_clip(); } -void fl_measure(const char* str, int& w, int& h) { +void fl_measure(const char* str, int& w, int& h, int draw_symbols) { if (!str || !*str) {w = 0; h = 0; return;} h = fl_height(); const char* p; @@ -304,10 +308,10 @@ void fl_measure(const char* str, int& w, int& h) { symtotal = symwidth[0] + symwidth[1]; for (p = str, lines=0; p;) { - e = expand(p, buf, w - symtotal, buflen, width, w != 0); + e = expand(p, buf, w - symtotal, buflen, width, w != 0, draw_symbols); if (int(width) > W) W = int(width); lines++; - if (!*e || *e == '@') break; + if (!*e || (*e == '@' && draw_symbols)) break; p = e; } @@ -323,5 +327,5 @@ void fl_measure(const char* str, int& w, int& h) { } // -// End of "$Id: fl_draw.cxx,v 1.6.2.4.2.5 2001/10/16 20:25:25 easysw Exp $". +// End of "$Id: fl_draw.cxx,v 1.6.2.4.2.6 2001/11/03 05:11:34 easysw Exp $". //