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
This commit is contained in:
Michael R Sweet 2001-11-03 05:11:34 +00:00
parent 7495dff247
commit d3acd6c475
10 changed files with 89 additions and 53 deletions

View File

@ -7,6 +7,13 @@ CHANGES IN FLTK 1.1.0
contains a number. contains a number.
- The Fl_Browser::make_visible() method now range checks - The Fl_Browser::make_visible() method now range checks
the input. 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 CHANGES IN FLTK 1.1.0b5

View File

@ -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). // 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* modal_;
static FL_EXPORT Fl_Window* grab_; static FL_EXPORT Fl_Window* grab_;
static FL_EXPORT int compose_state; static FL_EXPORT int compose_state;
static FL_EXPORT int visible_focus_;
static void damage(int x) {damage_ = x;} static void damage(int x) {damage_ = x;}
static FL_EXPORT void (*idle)(); static FL_EXPORT void (*idle)();
@ -212,10 +212,13 @@ public:
static FL_EXPORT void grab(Fl_Window&w) {grab(&w);} static FL_EXPORT void grab(Fl_Window&w) {grab(&w);}
static FL_EXPORT void release() {grab(0);} 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 #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 $".
// //

View File

@ -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). // 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() const;
FL_EXPORT void draw_box(Fl_Boxtype, Fl_Color) 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_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_focus(Fl_Boxtype, int,int,int,int) const;
FL_EXPORT void draw_label() const; FL_EXPORT void draw_label() const;
FL_EXPORT void draw_label(int, int, int, int) const; FL_EXPORT void draw_label(int, int, int, int) const;
@ -207,5 +207,5 @@ public:
#endif #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 $".
// //

View File

@ -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). // 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: // draw using current font:
FL_EXPORT void fl_draw(const char*, int x, int y); 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_draw(const char*, int n, int x, int y);
FL_EXPORT void fl_measure(const char*, int& x, int& y); 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); 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, FL_EXPORT void fl_draw(const char*, int,int,int,int, Fl_Align,
void (*callthis)(const char *, int n, int x, int y), void (*callthis)(const char *, int n, int x, int y),
Fl_Image* img=0); Fl_Image* img=0, int draw_symbols = 1);
// boxtypes: // boxtypes:
FL_EXPORT void fl_frame(const char* s, int x, int y, int w, int h); 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 #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 $".
// //

View File

@ -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). // Main event handling code for the Fast Light Tool Kit (FLTK).
// //
@ -53,6 +53,8 @@ int Fl::damage_,
Fl::e_keysym; Fl::e_keysym;
char *Fl::e_text = (char *)""; char *Fl::e_text = (char *)"";
int Fl::e_length; int Fl::e_length;
int Fl::visible_focus_ = 1;
// //
// 'Fl:event_inside()' - Return whether or not the mouse event is inside // '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 $".
// //

View File

@ -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). // 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()); lcol = fl_contrast(lcol, selection_color());
if (!active_r()) lcol = fl_inactive(lcol); if (!active_r()) lcol = fl_inactive(lcol);
fl_color(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... if (!e) break; // no more fields...
*e = column_char(); // put the seperator back *e = column_char(); // put the seperator back
x += w1; 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 $".
// //

View File

@ -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. // Fl_File_Browser routines.
// //
@ -325,7 +325,7 @@ Fl_File_Browser::item_draw(void *p, // I - List item data
*ptr = '\0'; *ptr = '\0';
fl_draw(fragment, x + width, y, w - width, fl_height(), 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... // Point back to the start of the fragment...
ptr = fragment; ptr = fragment;
@ -339,7 +339,7 @@ Fl_File_Browser::item_draw(void *p, // I - List item data
*ptr = '\0'; *ptr = '\0';
fl_draw(fragment, x + width, y, w - width, fl_height(), 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... // Advance to the next column...
column ++; column ++;
@ -362,7 +362,7 @@ Fl_File_Browser::item_draw(void *p, // I - List item data
*ptr = '\0'; *ptr = '\0';
fl_draw(fragment, x + width, y, w - width, fl_height(), 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 $".
// //

View File

@ -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). // 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; newval = 0; goto J1;
case FL_PUSH: case FL_PUSH:
case FL_DRAG: case FL_DRAG:
take_focus();
newval = Fl::event_inside(this); newval = Fl::event_inside(this);
J1: J1:
if (value(newval)) { 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 $".
// //

View File

@ -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). // 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... // draw a focus box for the widget...
void void
Fl_Widget::draw_focus(Fl_Boxtype B, int X, int Y, int W, int H) const { Fl_Widget::draw_focus(Fl_Boxtype B, int X, int Y, int W, int H) const {
if (!Fl::visible_focus()) return;
switch (B) { switch (B) {
case FL_DOWN_BOX: case FL_DOWN_BOX:
case FL_DOWN_FRAME: 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; 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_line_style(FL_DOT);
fl_rect(X + Fl::box_dx(B), Y + Fl::box_dy(B), fl_rect(X + Fl::box_dx(B), Y + Fl::box_dy(B),
W - Fl::box_dw(B) - 1, H - Fl::box_dh(B) - 1); W - Fl::box_dw(B) - 1, H - Fl::box_dh(B) - 1);
fl_line_style(FL_SOLID); 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 $".
// //

View File

@ -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). // 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. // Sets width to the width of the string in the current font.
static const char* 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* o = buf;
char* e = buf+(MAXBUF-4); char* e = buf+(MAXBUF-4);
underline_at = 0; 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 } else if (c == 0xA0) { // non-breaking space
*o++ = ' '; *o++ = ' ';
} else if (c == '@') { // Symbol??? } else if (c == '@') { // Symbol???
if (p[1] && p[1] != '@') break; if (p[1] && p[1] != '@' && draw_symbols) break;
*o++ = c; *o++ = c;
if (p[1]) p++; if (p[1]) p++;
} else { } else {
@ -114,7 +114,7 @@ void fl_draw(
int x, int y, int w, int h, // bounding box int x, int y, int w, int h, // bounding box
Fl_Align align, Fl_Align align,
void (*callthis)(const char*,int,int,int), void (*callthis)(const char*,int,int,int),
Fl_Image* img) { Fl_Image* img, int draw_symbols) {
const char* p; const char* p;
const char* e; const char* e;
char buf[MAXBUF]; char buf[MAXBUF];
@ -132,29 +132,32 @@ void fl_draw(
symbol[1][0] = '\0'; symbol[1][0] = '\0';
symwidth[1] = 0; symwidth[1] = 0;
if (str && str[0] == '@' && str[1] && str[1] != '@') { if (draw_symbols) {
// Start with a symbol... if (str && str[0] == '@' && str[1] && str[1] != '@') {
for (symptr = symbol[0]; // Start with a symbol...
*str && !isspace(*str) && symptr < (symbol[0] + sizeof(symbol[0]) - 1); for (symptr = symbol[0];
*symptr++ = *str++); *str && !isspace(*str) && symptr < (symbol[0] + sizeof(symbol[0]) - 1);
*symptr = '\0'; *symptr++ = *str++);
if (isspace(*str)) str++; *symptr = '\0';
symwidth[0] = min(w,h); if (isspace(*str)) str++;
} symwidth[0] = min(w,h);
}
if (str && (p = strrchr(str, '@')) != NULL && p > (str + 1)) { if (str && (p = strrchr(str, '@')) != NULL && p > (str + 1)) {
strncpy(symbol[1], p, sizeof(symbol[1]) - 1); strncpy(symbol[1], p, sizeof(symbol[1]) - 1);
symbol[1][sizeof(symbol[1]) - 1] = '\0'; symbol[1][sizeof(symbol[1]) - 1] = '\0';
symwidth[1] = min(w,h); symwidth[1] = min(w,h);
}
} }
symtotal = symwidth[0] + symwidth[1]; symtotal = symwidth[0] + symwidth[1];
if (str) { if (str) {
for (p = str, lines=0; p;) { 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++; lines++;
if (!*e || *e == '@') break; if (!*e || (*e == '@' && draw_symbols)) break;
p = e; p = e;
} }
} else lines = 0; } else lines = 0;
@ -195,7 +198,7 @@ void fl_draw(
int desc = fl_descent(); int desc = fl_descent();
for (p=str; ; ypos += height) { for (p=str; ; ypos += height) {
if (lines>1) e = expand(p, buf, w - symtotal, buflen, width, if (lines>1) e = expand(p, buf, w - symtotal, buflen, width,
align&FL_ALIGN_WRAP); align&FL_ALIGN_WRAP, draw_symbols);
else e = ""; else e = "";
if (width > symoffset) symoffset = (int)(width + 0.5); if (width > symoffset) symoffset = (int)(width + 0.5);
@ -257,15 +260,16 @@ void fl_draw(
const char* str, // the (multi-line) string const char* str, // the (multi-line) string
int x, int y, int w, int h, // bounding box int x, int y, int w, int h, // bounding box
Fl_Align align, Fl_Align align,
Fl_Image* img) { Fl_Image* img,
int draw_symbols) {
if ((!str || !*str) && !img) return; if ((!str || !*str) && !img) return;
if (w && h && !fl_not_clipped(x, y, w, h)) return; if (w && h && !fl_not_clipped(x, y, w, h)) return;
if (align & FL_ALIGN_CLIP) fl_clip(x, y, w, h); 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(); 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;} if (!str || !*str) {w = 0; h = 0; return;}
h = fl_height(); h = fl_height();
const char* p; const char* p;
@ -304,10 +308,10 @@ void fl_measure(const char* str, int& w, int& h) {
symtotal = symwidth[0] + symwidth[1]; symtotal = symwidth[0] + symwidth[1];
for (p = str, lines=0; p;) { 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); if (int(width) > W) W = int(width);
lines++; lines++;
if (!*e || *e == '@') break; if (!*e || (*e == '@' && draw_symbols)) break;
p = e; 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 $".
// //