1998-10-20 17:25:25 +04:00
|
|
|
//
|
|
|
|
// Input field test program for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-20 17:25:25 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Input.H>
|
|
|
|
#include <FL/Fl_Float_Input.H>
|
|
|
|
#include <FL/Fl_Int_Input.H>
|
|
|
|
#include <FL/Fl_Secret_Input.H>
|
|
|
|
#include <FL/Fl_Multiline_Input.H>
|
|
|
|
#include <FL/Fl_Button.H>
|
|
|
|
#include <FL/Fl_Toggle_Button.H>
|
2010-12-21 05:37:41 +03:00
|
|
|
#include <FL/Fl_Light_Button.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl_Color_Chooser.H>
|
2023-11-14 18:01:52 +03:00
|
|
|
#include <FL/Fl_Terminal.H>
|
2017-10-17 03:28:56 +03:00
|
|
|
|
|
|
|
#define TERMINAL_HEIGHT 120
|
|
|
|
|
|
|
|
// Globals
|
2023-11-14 18:01:52 +03:00
|
|
|
Fl_Terminal *G_tty = 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
void cb(Fl_Widget *ob) {
|
2017-10-17 03:28:56 +03:00
|
|
|
G_tty->printf("Callback for %s '%s'\n",ob->label(),((Fl_Input*)ob)->value());
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int when = 0;
|
|
|
|
Fl_Input *input[5];
|
|
|
|
|
|
|
|
void toggle_cb(Fl_Widget *o, long v) {
|
|
|
|
if (((Fl_Toggle_Button*)o)->value()) when |= v; else when &= ~v;
|
|
|
|
for (int i=0; i<5; i++) input[i]->when(when);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test(Fl_Input *i) {
|
1998-11-08 18:05:48 +03:00
|
|
|
if (i->changed()) {
|
2017-10-17 03:28:56 +03:00
|
|
|
i->clear_changed(); G_tty->printf("%s '%s'\n",i->label(),i->value());
|
2009-04-23 19:32:19 +04:00
|
|
|
char utf8buf[10];
|
2023-02-02 22:54:19 +03:00
|
|
|
int last = fl_utf8encode(i->index(i->insert_position()), utf8buf);
|
2009-04-23 19:32:19 +04:00
|
|
|
utf8buf[last] = 0;
|
2017-10-17 03:28:56 +03:00
|
|
|
G_tty->printf("Symbol at cursor position: %s\n", utf8buf);
|
1998-11-08 18:05:48 +03:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void button_cb(Fl_Widget *,void *) {
|
|
|
|
for (int i=0; i<5; i++) test(input[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void color_cb(Fl_Widget* button, void* v) {
|
|
|
|
Fl_Color c;
|
2010-12-08 17:00:35 +03:00
|
|
|
switch ((fl_intptr_t)v) {
|
2005-11-02 16:57:56 +03:00
|
|
|
case 0: c = FL_BACKGROUND2_COLOR; break;
|
1998-10-06 22:21:25 +04:00
|
|
|
case 1: c = FL_SELECTION_COLOR; break;
|
2005-11-02 16:57:56 +03:00
|
|
|
default: c = FL_FOREGROUND_COLOR; break;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
uchar r,g,b; Fl::get_color(c, r,g,b);
|
|
|
|
if (fl_color_chooser(0,r,g,b)) {
|
|
|
|
Fl::set_color(c,r,g,b); Fl::redraw();
|
2001-10-29 06:44:33 +03:00
|
|
|
button->labelcolor(fl_contrast(FL_BLACK,c));
|
1998-10-06 22:21:25 +04:00
|
|
|
button->redraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-21 05:37:41 +03:00
|
|
|
void tabnav_cb(Fl_Widget *w, void *v) {
|
|
|
|
Fl_Light_Button *b = (Fl_Light_Button*)w;
|
|
|
|
Fl_Multiline_Input *fmi = (Fl_Multiline_Input*)v;
|
|
|
|
fmi->tab_nav(b->value() ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void arrownav_cb(Fl_Widget *w, void *v) {
|
|
|
|
Fl_Light_Button *b = (Fl_Light_Button*)w;
|
|
|
|
Fl::option(Fl::OPTION_ARROW_FOCUS, b->value() ? true : false);
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
int main(int argc, char **argv) {
|
2020-07-01 19:03:10 +03:00
|
|
|
// the following two lines set the correct color scheme, so that
|
2005-11-02 16:57:56 +03:00
|
|
|
// calling fl_contrast below will return good results
|
|
|
|
Fl::args(argc, argv);
|
|
|
|
Fl::get_system_colors();
|
2017-10-17 03:28:56 +03:00
|
|
|
Fl_Window *window = new Fl_Window(400,420+TERMINAL_HEIGHT);
|
2023-11-14 18:01:52 +03:00
|
|
|
G_tty = new Fl_Terminal(0,420,window->w(),TERMINAL_HEIGHT);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
int y = 10;
|
|
|
|
input[0] = new Fl_Input(70,y,300,30,"Normal:"); y += 35;
|
2002-05-13 09:05:11 +04:00
|
|
|
input[0]->tooltip("Normal input field");
|
1998-10-06 22:21:25 +04:00
|
|
|
// input[0]->cursor_color(FL_SELECTION_COLOR);
|
2005-11-02 16:57:56 +03:00
|
|
|
// input[0]->maximum_size(20);
|
1998-10-06 22:21:25 +04:00
|
|
|
// input[0]->static_value("this is a testgarbage");
|
|
|
|
input[1] = new Fl_Float_Input(70,y,300,30,"Float:"); y += 35;
|
2008-04-23 03:33:17 +04:00
|
|
|
input[1]->tooltip("Input field for floating-point number (F1)");
|
|
|
|
input[1]->shortcut(FL_F+1);
|
1998-10-06 22:21:25 +04:00
|
|
|
input[2] = new Fl_Int_Input(70,y,300,30,"Int:"); y += 35;
|
2008-04-23 03:33:17 +04:00
|
|
|
input[2]->tooltip("Input field for integer number (F2)");
|
|
|
|
input[2]->shortcut(FL_F+2);
|
|
|
|
input[3] = new Fl_Secret_Input(70,y,300,30,"&Secret:"); y += 35;
|
|
|
|
input[3]->tooltip("Input field for password (Alt-S)");
|
|
|
|
input[4] = new Fl_Multiline_Input(70,y,300,100,"&Multiline:"); y += 105;
|
|
|
|
input[4]->tooltip("Input field for short text with newlines (Alt-M)");
|
2002-07-23 20:28:19 +04:00
|
|
|
input[4]->wrap(1);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
input[i]->when(0); input[i]->callback(cb);
|
|
|
|
}
|
|
|
|
int y1 = y;
|
|
|
|
|
|
|
|
Fl_Button *b;
|
2003-06-06 01:14:19 +04:00
|
|
|
b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_CHANGED");
|
1998-10-06 22:21:25 +04:00
|
|
|
b->callback(toggle_cb, FL_WHEN_CHANGED); y += 25;
|
2002-05-13 09:05:11 +04:00
|
|
|
b->tooltip("Do callback each time the text changes");
|
2003-06-06 01:14:19 +04:00
|
|
|
b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_RELEASE");
|
1998-10-06 22:21:25 +04:00
|
|
|
b->callback(toggle_cb, FL_WHEN_RELEASE); y += 25;
|
2002-05-13 09:05:11 +04:00
|
|
|
b->tooltip("Do callback when widget loses focus");
|
2003-06-06 01:14:19 +04:00
|
|
|
b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_ENTER_KEY");
|
1998-10-06 22:21:25 +04:00
|
|
|
b->callback(toggle_cb, FL_WHEN_ENTER_KEY); y += 25;
|
2002-05-13 09:05:11 +04:00
|
|
|
b->tooltip("Do callback when user hits Enter key");
|
2003-06-06 01:14:19 +04:00
|
|
|
b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_NOT_CHANGED");
|
1998-10-06 22:21:25 +04:00
|
|
|
b->callback(toggle_cb, FL_WHEN_NOT_CHANGED); y += 25;
|
2002-05-13 09:05:11 +04:00
|
|
|
b->tooltip("Do callback even if the text is not changed");
|
1998-10-06 22:21:25 +04:00
|
|
|
y += 5;
|
2010-12-21 05:37:41 +03:00
|
|
|
b = new Fl_Button(10,y,200,25,"&print changed()"); y += 25;
|
1998-10-06 22:21:25 +04:00
|
|
|
b->callback(button_cb);
|
2002-05-13 09:05:11 +04:00
|
|
|
b->tooltip("Print widgets that have changed() flag set");
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2010-12-21 05:37:41 +03:00
|
|
|
b = new Fl_Light_Button(10,y,100,25," Tab Nav");
|
|
|
|
b->tooltip("Control tab navigation for the multiline input field");
|
|
|
|
b->callback(tabnav_cb, (void*)input[4]);
|
|
|
|
b->value(input[4]->tab_nav() ? 1 : 0);
|
|
|
|
b = new Fl_Light_Button(110,y,100,25," Arrow Nav"); y += 25;
|
|
|
|
b->tooltip("Control horizontal arrow key focus navigation behavior.\n"
|
|
|
|
"e.g. Fl::OPTION_ARROW_FOCUS");
|
|
|
|
b->callback(arrownav_cb);
|
|
|
|
b->value(input[4]->tab_nav() ? 1 : 0);
|
|
|
|
b->value(Fl::option(Fl::OPTION_ARROW_FOCUS) ? 1 : 0);
|
|
|
|
|
2011-02-13 19:13:04 +03:00
|
|
|
b = new Fl_Button(220,y1,120,25,"color"); y1 += 25;
|
1998-10-06 22:21:25 +04:00
|
|
|
b->color(input[0]->color()); b->callback(color_cb, (void*)0);
|
2002-05-13 09:05:11 +04:00
|
|
|
b->tooltip("Color behind the text");
|
2011-02-13 19:13:04 +03:00
|
|
|
b = new Fl_Button(220,y1,120,25,"selection_color"); y1 += 25;
|
1998-10-06 22:21:25 +04:00
|
|
|
b->color(input[0]->selection_color()); b->callback(color_cb, (void*)1);
|
2001-10-29 06:44:33 +03:00
|
|
|
b->labelcolor(fl_contrast(FL_BLACK,b->color()));
|
2002-05-13 09:05:11 +04:00
|
|
|
b->tooltip("Color behind selected text");
|
2011-02-13 19:13:04 +03:00
|
|
|
b = new Fl_Button(220,y1,120,25,"textcolor"); y1 += 25;
|
1998-10-06 22:21:25 +04:00
|
|
|
b->color(input[0]->textcolor()); b->callback(color_cb, (void*)2);
|
2001-10-29 06:44:33 +03:00
|
|
|
b->labelcolor(fl_contrast(FL_BLACK,b->color()));
|
2002-05-13 09:05:11 +04:00
|
|
|
b->tooltip("Color of the text");
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
window->end();
|
2017-10-17 03:28:56 +03:00
|
|
|
window->resizable(G_tty);
|
1998-10-06 22:21:25 +04:00
|
|
|
window->show(argc,argv);
|
|
|
|
return Fl::run();
|
|
|
|
}
|