Backported the fltk2.0 tooltips. This may be somewhat binary incompatable

as Fl_Widget::tooltip(x) is no longer an inline (though the previous version
will work if there is at least one call to the new one). It may be better
to just enable tooltips all the time. Also Fl_Tooltip::enable() is changed,
but few programs call that.


git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@2210 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Bill Spitzak 2002-05-13 05:05:11 +00:00
parent a35c5a6a2e
commit 80465e4bff
7 changed files with 227 additions and 244 deletions

View File

@ -1,5 +1,5 @@
// //
// "$Id: Fl_Tooltip.H,v 1.16.2.7 2002/04/14 02:43:48 easysw Exp $" // "$Id: Fl_Tooltip.H,v 1.16.2.8 2002/05/13 05:05:11 spitzak Exp $"
// //
// Tooltip header file for the Fast Light Tool Kit (FLTK). // Tooltip header file for the Fast Light Tool Kit (FLTK).
// //
@ -23,59 +23,42 @@
// Please report all bugs and problems to "fltk-bugs@fltk.org". // Please report all bugs and problems to "fltk-bugs@fltk.org".
// //
#ifndef _Fl_Tooltip_H_ #ifndef Fl_Tooltip_H
#define _Fl_Tooltip_H_ #define Fl_Tooltip_H
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/Fl_Widget.H> #include <FL/Fl_Widget.H>
class Fl_Tooltip_Box;
class Fl_Tooltip_Window;
class FL_EXPORT Fl_Tooltip { class FL_EXPORT Fl_Tooltip {
friend class Fl_Tooltip_Box;
friend class Fl_Tooltip_Window;
friend class Fl_Widget;
static float delay_;
static Fl_Tooltip_Box *box;
static Fl_Tooltip_Window *window;
static Fl_Widget *widget;
static int shown;
static unsigned color_;
static int font_;
static int size_;
static void tooltip_timeout(void *);
static void tooltip_exit(Fl_Widget *);
static void (*tooltip_callback_)(void *);
static void (*tooltip_exit_)(void *);
public: public:
// These functions are user-called functions
static float delay() { return delay_; } static float delay() { return delay_; }
static void delay(float f) { delay_ = (f < 0.1f) ? 0.1f : f; } static void delay(float f) { delay_ = f; }
static int enabled() { return enabled_; }
static void enable(int b = 1) { enabled_ = b;}
static void disable() { enabled_ = 0; }
static void (*enter)(Fl_Widget* w);
static void enter_area(Fl_Widget* w, int X, int Y, int W, int H, const char* tip);
static void (*exit)(Fl_Widget *w);
static int font() { return font_; } static int font() { return font_; }
static int size() { return size_; } static int size() { return size_; }
static void font(int i) { font_ = i; } static void font(int i) { font_ = i; }
static void size(int s) { size_ = s; } static void size(int s) { size_ = s; }
static void color(unsigned c) { color_ = c; } static void color(unsigned c) { color_ = c; }
static Fl_Color color() { return (Fl_Color)color_; } static Fl_Color color() { return (Fl_Color)color_; }
static void textcolor(unsigned c) { textcolor_ = c; }
static void enter(Fl_Widget *w); static Fl_Color textcolor() { return (Fl_Color)textcolor_; }
static void exit(Fl_Widget *w); private:
static int enabled() {return tooltip_callback_ != 0;} static float delay_;
static void enable(int b = 1) {if (!b) enter(0); tooltip_callback_ = b ? tooltip_timeout : 0; tooltip_exit_ = b ? (void (*)(void *))tooltip_exit : 0;} static int enabled_;
static void disable() {enter(0); tooltip_callback_ = 0; tooltip_exit_ = 0;} static unsigned color_;
static unsigned textcolor_;
static int font_;
static int size_;
}; };
#endif #endif
// //
// End of "$Id: Fl_Tooltip.H,v 1.16.2.7 2002/04/14 02:43:48 easysw Exp $". // End of "$Id: Fl_Tooltip.H,v 1.16.2.8 2002/05/13 05:05:11 spitzak Exp $".
// //

View File

@ -1,5 +1,5 @@
// //
// "$Id: Fl_Widget.H,v 1.6.2.4.2.13 2002/01/01 15:11:28 easysw Exp $" // "$Id: Fl_Widget.H,v 1.6.2.4.2.14 2002/05/13 05:05:11 spitzak Exp $"
// //
// Widget header file for the Fast Light Tool Kit (FLTK). // Widget header file for the Fast Light Tool Kit (FLTK).
// //
@ -143,7 +143,7 @@ public:
void deimage(Fl_Image* a) {label_.deimage=a;} void deimage(Fl_Image* a) {label_.deimage=a;}
void deimage(Fl_Image& a) {label_.deimage=&a;} void deimage(Fl_Image& a) {label_.deimage=&a;}
const char *tooltip() const {return tooltip_;} const char *tooltip() const {return tooltip_;}
void tooltip(const char *t) {tooltip_=t;} FL_EXPORT void tooltip(const char *t);
Fl_Callback_p callback() const {return callback_;} Fl_Callback_p callback() const {return callback_;}
void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;} void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
void callback(Fl_Callback* c) {callback_=c;} void callback(Fl_Callback* c) {callback_=c;}
@ -207,5 +207,5 @@ public:
#endif #endif
// //
// End of "$Id: Fl_Widget.H,v 1.6.2.4.2.13 2002/01/01 15:11:28 easysw Exp $". // End of "$Id: Fl_Widget.H,v 1.6.2.4.2.14 2002/05/13 05:05:11 spitzak Exp $".
// //

View File

@ -1,5 +1,5 @@
// //
// "$Id: Fl.cxx,v 1.24.2.41.2.26 2002/04/13 22:17:46 easysw Exp $" // "$Id: Fl.cxx,v 1.24.2.41.2.27 2002/05/13 05:05:11 spitzak Exp $"
// //
// Main event handling code for the Fast Light Tool Kit (FLTK). // Main event handling code for the Fast Light Tool Kit (FLTK).
// //
@ -423,8 +423,8 @@ void Fl::belowmouse(Fl_Widget *o) {
if (grab()) return; // don't do anything while grab is on if (grab()) return; // don't do anything while grab is on
Fl_Widget *p = belowmouse_; Fl_Widget *p = belowmouse_;
if (o != p) { if (o != p) {
if (!dnd_flag) Fl_Tooltip::enter(o);
belowmouse_ = o; belowmouse_ = o;
if (!dnd_flag) Fl_Tooltip::enter(o);
for (; p && !p->contains(o); p = p->parent()) { for (; p && !p->contains(o); p = p->parent()) {
p->handle(dnd_flag ? FL_DND_LEAVE : FL_LEAVE); p->handle(dnd_flag ? FL_DND_LEAVE : FL_LEAVE);
} }
@ -440,6 +440,10 @@ Fl_Window *fl_xmousewin;// which window X thinks has FL_ENTER
Fl_Window *Fl::grab_; // most recent Fl::grab() Fl_Window *Fl::grab_; // most recent Fl::grab()
Fl_Window *Fl::modal_; // topmost modal() window Fl_Window *Fl::modal_; // topmost modal() window
static void nothing(Fl_Widget *) {}
void (*Fl_Tooltip::enter)(Fl_Widget *) = nothing;
void (*Fl_Tooltip::exit)(Fl_Widget *) = nothing;
// Update modal(), focus() and other state according to system state, // Update modal(), focus() and other state according to system state,
// and send FL_ENTER, FL_LEAVE, FL_FOCUS, and/or FL_UNFOCUS events. // and send FL_ENTER, FL_LEAVE, FL_FOCUS, and/or FL_UNFOCUS events.
// This is the only function that produces these events in response // This is the only function that produces these events in response
@ -550,7 +554,7 @@ int Fl::handle(int event, Fl_Window* window)
return 1; return 1;
case FL_PUSH: case FL_PUSH:
if (!pushed()) Fl_Tooltip::enter(0); Fl_Tooltip::enter((Fl_Widget*)0);
if (grab()) w = grab(); if (grab()) w = grab();
else if (modal() && w != modal()) return 0; else if (modal() && w != modal()) return 0;
pushed_ = w; pushed_ = w;
@ -623,8 +627,6 @@ int Fl::handle(int event, Fl_Window* window)
e_number = event = FL_SHORTCUT; e_number = event = FL_SHORTCUT;
case FL_SHORTCUT: case FL_SHORTCUT:
Fl_Tooltip::enter((Fl_Widget*)0);
if (grab()) {w = grab(); break;} // send it to grab window if (grab()) {w = grab(); break;} // send it to grab window
// Try it as shortcut, sending to mouse widget and all parents: // Try it as shortcut, sending to mouse widget and all parents:
@ -753,7 +755,7 @@ void Fl_Window::hide() {
delete x; delete x;
// Hide any visible tooltips... // Hide any visible tooltips...
Fl_Tooltip::enter(0); //Fl_Tooltip::enter(0);
} }
Fl_Window::~Fl_Window() { Fl_Window::~Fl_Window() {
@ -890,5 +892,5 @@ void Fl_Window::flush() {
} }
// //
// End of "$Id: Fl.cxx,v 1.24.2.41.2.26 2002/04/13 22:17:46 easysw Exp $". // End of "$Id: Fl.cxx,v 1.24.2.41.2.27 2002/05/13 05:05:11 spitzak Exp $".
// //

View File

@ -1,5 +1,5 @@
// //
// "$Id: Fl_Group.cxx,v 1.8.2.8.2.13 2002/05/10 00:18:37 easysw Exp $" // "$Id: Fl_Group.cxx,v 1.8.2.8.2.14 2002/05/13 05:05:11 spitzak Exp $"
// //
// Group widget for the Fast Light Tool Kit (FLTK). // Group widget for the Fast Light Tool Kit (FLTK).
// //
@ -34,7 +34,6 @@
#include <FL/Fl_Window.H> #include <FL/Fl_Window.H>
#include <FL/fl_draw.H> #include <FL/fl_draw.H>
#include <stdlib.h> #include <stdlib.h>
#include <FL/Fl_Tooltip.H> // tooltip
Fl_Group* Fl_Group::current_; Fl_Group* Fl_Group::current_;
@ -139,11 +138,9 @@ int Fl_Group::handle(int event) {
return 0; return 0;
case FL_KEYBOARD: case FL_KEYBOARD:
Fl_Tooltip::exit(this); // tooltip
return navigation(navkey()); return navigation(navkey());
case FL_SHORTCUT: case FL_SHORTCUT:
Fl_Tooltip::exit(this); // tooltip
for (i = children(); i--;) { for (i = children(); i--;) {
o = a[i]; o = a[i];
if (o->takesevents() && Fl::event_inside(o) && send(o,FL_SHORTCUT)) if (o->takesevents() && Fl::event_inside(o) && send(o,FL_SHORTCUT))
@ -158,8 +155,6 @@ int Fl_Group::handle(int event) {
return 0; return 0;
case FL_ENTER: case FL_ENTER:
Fl_Tooltip::enter(this); // tooltip
case FL_MOVE: case FL_MOVE:
for (i = children(); i--;) { for (i = children(); i--;) {
o = a[i]; o = a[i];
@ -192,7 +187,6 @@ int Fl_Group::handle(int event) {
return 0; return 0;
case FL_PUSH: case FL_PUSH:
Fl_Tooltip::exit(this); // tooltip
for (i = children(); i--;) { for (i = children(); i--;) {
o = a[i]; o = a[i];
if (o->takesevents() && Fl::event_inside(o)) { if (o->takesevents() && Fl::event_inside(o)) {
@ -235,9 +229,6 @@ int Fl_Group::handle(int event) {
} }
return 1; return 1;
case FL_LEAVE: // tooltip
Fl_Tooltip::exit(this); // tooltip
default: default:
// For all other events, try to give to each child, starting at focus: // For all other events, try to give to each child, starting at focus:
for (i = 0; i < children(); i ++) for (i = 0; i < children(); i ++)
@ -589,5 +580,5 @@ void Fl_Group::draw_outside_label(const Fl_Widget& w) const {
} }
// //
// End of "$Id: Fl_Group.cxx,v 1.8.2.8.2.13 2002/05/10 00:18:37 easysw Exp $". // End of "$Id: Fl_Group.cxx,v 1.8.2.8.2.14 2002/05/13 05:05:11 spitzak Exp $".
// //

View File

@ -1,5 +1,5 @@
// //
// "$Id: Fl_Tooltip.cxx,v 1.38.2.16 2002/05/02 15:02:31 easysw Exp $" // "$Id: Fl_Tooltip.cxx,v 1.38.2.17 2002/05/13 05:05:11 spitzak Exp $"
// //
// Tooltip source file for the Fast Light Tool Kit (FLTK). // Tooltip source file for the Fast Light Tool Kit (FLTK).
// //
@ -23,203 +23,158 @@
// Please report all bugs and problems to "fltk-bugs@fltk.org". // Please report all bugs and problems to "fltk-bugs@fltk.org".
// //
#include <FL/Fl.H>
#include <FL/Fl_Menu_Window.H>
#include <FL/Fl_Box.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Tooltip.H> #include <FL/Fl_Tooltip.H>
#include <FL/fl_draw.H>
#include <FL/Fl_Menu_Window.H>
#include <stdio.h> #include <stdio.h>
// float Fl_Tooltip::delay_ = 1.0f;
// Fl_Tooltip global variables... int Fl_Tooltip::enabled_ = 1;
//
void (*Fl_Tooltip::tooltip_callback_)(void *) = Fl_Tooltip::tooltip_timeout;
void (*Fl_Tooltip::tooltip_exit_)(void *) = (void (*)(void *))Fl_Tooltip::tooltip_exit;
float Fl_Tooltip::delay_ = 0.5;
Fl_Tooltip_Box *Fl_Tooltip::box = 0;
Fl_Tooltip_Window *Fl_Tooltip::window = 0;
Fl_Widget *Fl_Tooltip::widget = 0;
int Fl_Tooltip::shown = 0;
unsigned Fl_Tooltip::color_ = fl_color_cube(FL_NUM_RED - 1, unsigned Fl_Tooltip::color_ = fl_color_cube(FL_NUM_RED - 1,
FL_NUM_GREEN - 1, FL_NUM_GREEN - 1,
FL_NUM_BLUE - 2); FL_NUM_BLUE - 2);
unsigned Fl_Tooltip::textcolor_ = FL_BLACK;
int Fl_Tooltip::font_ = FL_HELVETICA; int Fl_Tooltip::font_ = FL_HELVETICA;
int Fl_Tooltip::size_ = FL_NORMAL_SIZE; int Fl_Tooltip::size_ = FL_NORMAL_SIZE;
#define MAX_WIDTH 400
// class Fl_TooltipBox : public Fl_Menu_Window {
// Tooltip window class...
//
class Fl_Tooltip_Window : public Fl_Menu_Window {
public:
FL_EXPORT ~Fl_Tooltip_Window() {}
Fl_Tooltip_Window(int W, int H, const char *l = 0)
: Fl_Menu_Window(W,H,l) { set_override(); }
Fl_Tooltip_Window(int X, int Y, int W, int H, const char *l = 0)
: Fl_Menu_Window(X,Y,W,H,l) {}
};
//
// Tooltip label class...
//
class Fl_Tooltip_Box : public Fl_Box {
public: public:
Fl_TooltipBox() : Fl_Menu_Window(0, 0) {
Fl_Tooltip_Box() : Fl_Box(0,0,10,10) { set_override();
color(Fl_Tooltip::color_); end();
align(FL_ALIGN_CENTER);
box(FL_BORDER_BOX);
Fl_Tooltip::widget = 0;
}
~Fl_Tooltip_Box() { }
void draw() {
tooltip(0); // Just in case
if (!Fl_Tooltip::widget || !Fl_Tooltip::widget->tooltip())
return;
Fl_Window *widgetWindow = Fl_Tooltip::widget->window();
if (!widgetWindow) {
// printf("!widgetWindow\n");
return;
}
int ww, hh;
ww = 0;
labelfont(Fl_Tooltip::font_);
labelsize(Fl_Tooltip::size_);
color(Fl_Tooltip::color_);
fl_font(Fl_Tooltip::font_, Fl_Tooltip::size_);
fl_measure(Fl_Tooltip::widget->tooltip(), ww, hh);
label(Fl_Tooltip::widget->tooltip());
int ox = Fl::event_x_root() + 10;
int oy = Fl::event_y_root() + 10;
if (ox >= (Fl::w() - ww - 6))
ox = Fl::w() - ww - 6;
if (oy >= (Fl::h() - hh - 6))
oy = widgetWindow->y_root() + Fl_Tooltip::widget->y() - hh - 6;
parent()->resize(ox, oy, ww+6, hh+6);
draw_box();
draw_label();
} }
void draw();
void layout();
#ifdef _WIN32
// You have to destroy the window or it will not raise next time:
void hide() {destroy();}
#endif
}; };
static const char* tip;
static Fl_Widget* widget;
static Fl_TooltipBox *window = 0;
static int X,Y,W,H;
// This function is called by widgets void Fl_TooltipBox::layout() {
// when the pointer enters them fl_font(Fl_Tooltip::font(), Fl_Tooltip::size());
void int ww, hh;
Fl_Tooltip::enter(Fl_Widget *w) { ww = MAX_WIDTH;
// printf("Fl_Tooltip::enter(%p)\n", w); fl_measure(tip, ww, hh, FL_ALIGN_LEFT|FL_ALIGN_WRAP|FL_ALIGN_INSIDE);
// if (w) { ww += 6; hh += 6;
// printf(" label() = \"%s\"\n", w->label() ? w->label() : "(null)");
// printf(" visible() = %d\n", w->visible()); // find position on the screen of the widget:
// printf(" active() = %d\n", w->active()); int ox = Fl::event_x_root();
// } //int ox = X+W/2;
Fl_Widget* temp = w; int oy = Y + H+2;
while (temp && !temp->tooltip()) { for (Fl_Widget* p = widget; p; p = p->window()) {
if (temp == window) return; // Don't do anything if pointed at tooltip //ox += p->x();
temp = temp->parent(); oy += p->y();
} }
if (ox+ww > Fl::w()) ox = Fl::w() - ww;
if ((!w || !w->tooltip()) && tooltip_callback_) { if (ox < 0) ox = 0;
// puts("Hiding tooltip..."); if (H > 30) {
Fl::remove_timeout(tooltip_callback_); oy = Fl::event_y_root()+13;
if (window) window->hide(); if (oy+hh > Fl::h()) oy -= 23+hh;
shown = 0;
return;
}
if (!tooltip_callback_ || !w || !w->tooltip()) return;
Fl::remove_timeout(tooltip_callback_);
if (window && window->shown()) (*tooltip_callback_)(w);
else Fl::add_timeout(delay_, tooltip_callback_, w);
}
// This function must be called when
// an event != FL_MOVE has occured in
// the widget
void
Fl_Tooltip::exit(Fl_Widget *w) {
// printf("Fl_Tooltip::exit(%p)\n", w);
if (tooltip_exit_) tooltip_exit_(w);
}
void
Fl_Tooltip::tooltip_exit(Fl_Widget *w) {
// printf("Fl_Tooltip::tooltip_exit(%p), widget = %p, window = %p, shown = %d\n",
// w, widget, window, shown);
if (!w || w != widget) return;
Fl::remove_timeout(tooltip_callback_);
widget = 0;
if (window) {
// puts("Hiding tooltip...");
window->hide();
shown = 0;
}
}
void
Fl_Tooltip::tooltip_timeout(void *v) {
// printf("Fl_Tooltip::tooltip_timeout(%p)\n", v);
if (!window) {
Fl_Group* saveCurrent = Fl_Group::current();
Fl_Group::current(0);
window = new Fl_Tooltip_Window(0, 0, 10, 10, 0);
window->clear_border();
window->box(FL_NO_BOX);
window->set_override();
window->begin();
box = new Fl_Tooltip_Box;
box->color(FL_YELLOW);
box->align(FL_ALIGN_CENTER);
window->resizable(box);
window->end();
Fl_Group::current(saveCurrent);
// printf("Fl_Tooltip::window = %p\n", window);
// printf("Fl_Tooltip::box = %p\n", box);
}
if (!v)
return;
if (shown && widget != (Fl_Widget *)v) {
tooltip_exit(widget);
}
widget = (Fl_Widget*) v;
Fl_Window *widgetWindow = widget->window();
if (widgetWindow) {
// puts("Showing tooltip");
window->show();
shown = 1;
} else { } else {
widget = 0; if (oy+hh > Fl::h()) oy -= (4+hh+H);
}
if (oy < 0) oy = 0;
resize(ox, oy, ww, hh);
}
void Fl_TooltipBox::draw() {
draw_box(FL_BORDER_BOX, 0, 0, w(), h(), Fl_Tooltip::color());
fl_color(Fl_Tooltip::textcolor());
fl_font(Fl_Tooltip::font(), Fl_Tooltip::size());
fl_draw(tip, 3, 3, w()-6, h()-6, Fl_Align(FL_ALIGN_LEFT|FL_ALIGN_WRAP));
}
static char recent_tooltip;
static void recent_timeout(void*) {
recent_tooltip = 0;
}
static char recursion;
static void tooltip_timeout(void*) {
if (recursion) return;
recursion = 1;
if (!tip || !*tip) return;
//if (Fl::grab()) return;
if (!window) window = new Fl_TooltipBox;
// this cast bypasses the normal Fl_Window label() code:
((Fl_Widget*)window)->label(tip);
window->layout();
window->redraw();
window->show();
Fl::remove_timeout(recent_timeout);
recent_tooltip = 1;
recursion = 0;
}
// This is called when a widget is destroyed:
static void
tt_exit(Fl_Widget *w) {
if (w && w == widget) Fl_Tooltip::enter_area(0,0,0,0,0,0);
}
static void
tt_enter(Fl_Widget* widget) {
// find the enclosing group with a tooltip:
Fl_Widget* w = widget;
while (w && !w->tooltip()) {
if (w == window) return; // don't do anything if pointed at tooltip
w = w->parent();
}
if (!w) {
Fl_Tooltip::enter_area(0, 0, 0, 0, 0, 0);
} else {
Fl_Tooltip::enter_area(widget,0,0,widget->w(), widget->h(), w->tooltip());
} }
} }
void
Fl_Tooltip::enter_area(Fl_Widget* wid, int x,int y,int w,int h, const char* t)
{
if (recursion) return;
Fl::remove_timeout(tooltip_timeout);
Fl::remove_timeout(recent_timeout);
if (t && *t && enabled()) { // there is a tooltip
// do nothing if it is the same:
if (wid==widget && x==X && y==Y && w==W && h==H && t==tip) return;
// remember it:
widget = wid; X = x; Y = y; W = w; H = h; tip = t;
if (recent_tooltip || Fl_Tooltip::delay() < .1) {
// switch directly from a previous tooltip to the new one:
tooltip_timeout(0);
} else {
if (window) window->hide();
Fl::add_timeout(Fl_Tooltip::delay(), tooltip_timeout);
}
} else { // no tooltip
tip = 0;
widget = 0;
if (window) window->hide();
if (recent_tooltip) Fl::add_timeout(.2, recent_timeout);
}
}
void Fl_Widget::tooltip(const char *tt) {
static char beenhere = 0;
if (!beenhere) {
beenhere = 1;
Fl_Tooltip::enter = tt_enter;
Fl_Tooltip::exit = tt_exit;
}
tooltip_ = tt;
}
// //
// End of "$Id: Fl_Tooltip.cxx,v 1.38.2.16 2002/05/02 15:02:31 easysw Exp $". // End of "$Id: Fl_Tooltip.cxx,v 1.38.2.17 2002/05/13 05:05:11 spitzak Exp $".
// //

View File

@ -1,5 +1,5 @@
// //
// "$Id: input.cxx,v 1.5.2.4.2.2 2002/01/01 15:11:33 easysw Exp $" // "$Id: input.cxx,v 1.5.2.4.2.3 2002/05/13 05:05:11 spitzak Exp $"
// //
// Input field test program for the Fast Light Tool Kit (FLTK). // Input field test program for the Fast Light Tool Kit (FLTK).
// //
@ -77,13 +77,18 @@ int main(int argc, char **argv) {
int y = 10; int y = 10;
input[0] = new Fl_Input(70,y,300,30,"Normal:"); y += 35; input[0] = new Fl_Input(70,y,300,30,"Normal:"); y += 35;
input[0]->tooltip("Normal input field");
// input[0]->cursor_color(FL_SELECTION_COLOR); // input[0]->cursor_color(FL_SELECTION_COLOR);
// input[0]->maximum_size(20); // input[0]->maximum_size(20);
// input[0]->static_value("this is a testgarbage"); // input[0]->static_value("this is a testgarbage");
input[1] = new Fl_Float_Input(70,y,300,30,"Float:"); y += 35; input[1] = new Fl_Float_Input(70,y,300,30,"Float:"); y += 35;
input[1]->tooltip("Input field for floating-point number");
input[2] = new Fl_Int_Input(70,y,300,30,"Int:"); y += 35; input[2] = new Fl_Int_Input(70,y,300,30,"Int:"); y += 35;
input[2]->tooltip("Input field for integer number");
input[3] = new Fl_Secret_Input(70,y,300,30,"Secret:"); y += 35; input[3] = new Fl_Secret_Input(70,y,300,30,"Secret:"); y += 35;
input[3]->tooltip("Input field for password");
input[4] = new Fl_Multiline_Input(70,y,300,100,"Multiline:"); y += 105; input[4] = new Fl_Multiline_Input(70,y,300,100,"Multiline:"); y += 105;
input[4]->tooltip("Input field for short text with newlines");
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
input[i]->when(0); input[i]->callback(cb); input[i]->when(0); input[i]->callback(cb);
@ -93,24 +98,32 @@ int main(int argc, char **argv) {
Fl_Button *b; Fl_Button *b;
b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&CHANGED"); b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&CHANGED");
b->callback(toggle_cb, FL_WHEN_CHANGED); y += 25; b->callback(toggle_cb, FL_WHEN_CHANGED); y += 25;
b->tooltip("Do callback each time the text changes");
b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&RELEASE"); b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&RELEASE");
b->callback(toggle_cb, FL_WHEN_RELEASE); y += 25; b->callback(toggle_cb, FL_WHEN_RELEASE); y += 25;
b->tooltip("Do callback when widget loses focus");
b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&ENTER_KEY"); b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&ENTER_KEY");
b->callback(toggle_cb, FL_WHEN_ENTER_KEY); y += 25; b->callback(toggle_cb, FL_WHEN_ENTER_KEY); y += 25;
b->tooltip("Do callback when user hits Enter key");
b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&NOT_CHANGED"); b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_&NOT_CHANGED");
b->callback(toggle_cb, FL_WHEN_NOT_CHANGED); y += 25; b->callback(toggle_cb, FL_WHEN_NOT_CHANGED); y += 25;
b->tooltip("Do callback even if the text is not changed");
y += 5; y += 5;
b = new Fl_Button(10,y,200,25,"&print changed()"); b = new Fl_Button(10,y,200,25,"&print changed()");
b->callback(button_cb); b->callback(button_cb);
b->tooltip("Print widgets that have changed() flag set");
b = new Fl_Button(220,y1,100,25,"color"); y1 += 25; b = new Fl_Button(220,y1,100,25,"color"); y1 += 25;
b->color(input[0]->color()); b->callback(color_cb, (void*)0); b->color(input[0]->color()); b->callback(color_cb, (void*)0);
b->tooltip("Color behind the text");
b = new Fl_Button(220,y1,100,25,"selection_color"); y1 += 25; b = new Fl_Button(220,y1,100,25,"selection_color"); y1 += 25;
b->color(input[0]->selection_color()); b->callback(color_cb, (void*)1); b->color(input[0]->selection_color()); b->callback(color_cb, (void*)1);
b->labelcolor(fl_contrast(FL_BLACK,b->color())); b->labelcolor(fl_contrast(FL_BLACK,b->color()));
b->tooltip("Color behind selected text");
b = new Fl_Button(220,y1,100,25,"textcolor"); y1 += 25; b = new Fl_Button(220,y1,100,25,"textcolor"); y1 += 25;
b->color(input[0]->textcolor()); b->callback(color_cb, (void*)2); b->color(input[0]->textcolor()); b->callback(color_cb, (void*)2);
b->labelcolor(fl_contrast(FL_BLACK,b->color())); b->labelcolor(fl_contrast(FL_BLACK,b->color()));
b->tooltip("Color of the text");
window->end(); window->end();
window->show(argc,argv); window->show(argc,argv);
@ -118,5 +131,5 @@ int main(int argc, char **argv) {
} }
// //
// End of "$Id: input.cxx,v 1.5.2.4.2.2 2002/01/01 15:11:33 easysw Exp $". // End of "$Id: input.cxx,v 1.5.2.4.2.3 2002/05/13 05:05:11 spitzak Exp $".
// //

View File

@ -1,5 +1,5 @@
// //
// "$Id: symbols.cxx,v 1.4.2.3.2.2 2002/01/01 15:11:33 easysw Exp $" // "$Id: symbols.cxx,v 1.4.2.3.2.3 2002/05/13 05:05:11 spitzak Exp $"
// //
// Symbol test program for the Fast Light Tool Kit (FLTK). // Symbol test program for the Fast Light Tool Kit (FLTK).
// //
@ -26,19 +26,46 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <FL/Fl.H> #include <FL/Fl.H>
#include <FL/Fl_Single_Window.H> #include <FL/Fl_Single_Window.H>
#include <FL/Fl_Box.H> #include <FL/Fl_Box.H>
#include <FL/Fl_Value_Slider.H>
#include <FL/fl_draw.H> #include <FL/fl_draw.H>
int N = 0; int N = 0;
#define W 60 #define W 70
#define H 60 #define H 70
#define ROWS 5 #define ROWS 5
#define COLS 5 #define COLS 5
Fl_Window *window; Fl_Window *window;
void slider_cb(Fl_Widget *w, void *data) {
static char buf[80];
int val = (int)(((Fl_Value_Slider*)w)->value());
Fl_Window *win = (Fl_Window*)w->parent(); // get parent window
for (int i = win->children(); i--; ) { // all window children
Fl_Widget *wc = win->child(i);
const char *l = wc->label();
if ( *l == '@' ) { // all children with '@'
if ( *(++l) == '@' ) { // ascii legend?
l++;
while (isdigit(*l)) { l++; }
if (val == 0) { sprintf(buf, "@@%s", l); }
else { sprintf(buf, "@@%d%s", val, l); }
} else { // box with symbol
while (isdigit(*l)) { l++; }
if (val == 0) { sprintf(buf, "@%s", l); }
else { sprintf(buf, "@%d%s", val, l); }
}
free((void*)(wc->label()));
wc->label(strdup(buf));
}
}
win->redraw();
}
void bt(const char *name) { void bt(const char *name) {
int x = N%COLS; int x = N%COLS;
int y = N/COLS; int y = N/COLS;
@ -50,12 +77,12 @@ void bt(const char *name) {
Fl_Box *a = new Fl_Box(FL_NO_BOX,x,y,W-20,H-20,strdup(buf)); Fl_Box *a = new Fl_Box(FL_NO_BOX,x,y,W-20,H-20,strdup(buf));
a->align(FL_ALIGN_BOTTOM); a->align(FL_ALIGN_BOTTOM);
a->labelsize(11); a->labelsize(11);
Fl_Box *b = new Fl_Box(FL_UP_BOX,x,y,W-20,H-20,name); Fl_Box *b = new Fl_Box(FL_UP_BOX,x,y,W-20,H-20,strdup(name));
b->labelcolor(FL_DARK3); b->labelcolor(FL_DARK3);
} }
int main(int argc, char ** argv) { int main(int argc, char ** argv) {
window = new Fl_Single_Window(COLS*W,ROWS*H+20); window = new Fl_Single_Window(COLS*W,ROWS*H+60);
bt("@->"); bt("@->");
bt("@>"); bt("@>");
bt("@>>"); bt("@>>");
@ -81,11 +108,23 @@ bt("@line");
bt("@menu"); bt("@menu");
bt("@UpArrow"); bt("@UpArrow");
bt("@DnArrow"); bt("@DnArrow");
Fl_Value_Slider slider((int)(window->w()*.10+.5),
window->h()-40,
(int)(window->w()*.80+.5),
16,
"Orientation");
slider.type(FL_HORIZONTAL);
slider.range(0.0, 9.0);
slider.value(0.0);
slider.step(1);
slider.callback(slider_cb, &slider);
window->resizable(window); window->resizable(window);
window->show(argc,argv); window->show(argc,argv);
return Fl::run(); return Fl::run();
} }
// //
// End of "$Id: symbols.cxx,v 1.4.2.3.2.2 2002/01/01 15:11:33 easysw Exp $". // End of "$Id: symbols.cxx,v 1.4.2.3.2.3 2002/05/13 05:05:11 spitzak Exp $".
// //