2005-11-27 08:15:47 +03:00
|
|
|
//
|
2024-06-27 04:19:26 +03:00
|
|
|
// Test program for Fl_Input_Choice and Fl_Choice
|
2005-02-25 00:14:22 +03:00
|
|
|
//
|
2024-06-27 04:19:26 +03:00
|
|
|
// Copyright 1998-2024 by Bill Spitzak and others.
|
2005-02-25 00:14:22 +03: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:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2011-07-19 08:49:30 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2011-07-19 08:49:30 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2005-02-25 00:14:22 +03:00
|
|
|
//
|
|
|
|
|
2009-04-21 13:09:37 +04:00
|
|
|
#include <FL/Fl_Double_Window.H>
|
2005-02-25 00:14:22 +03:00
|
|
|
#include <FL/Fl_Input_Choice.H>
|
2024-06-27 04:19:26 +03:00
|
|
|
#include <FL/Fl_Choice.H>
|
2024-06-27 01:40:41 +03:00
|
|
|
#include <FL/Fl_Scheme_Choice.H>
|
2024-06-27 04:19:26 +03:00
|
|
|
#include <FL/Fl_Check_Button.H>
|
2023-11-14 18:01:52 +03:00
|
|
|
#include <FL/Fl_Terminal.H>
|
2017-10-17 03:28:56 +03:00
|
|
|
|
2024-06-27 04:19:26 +03:00
|
|
|
#define TERMINAL_HEIGHT 150
|
2017-10-17 03:28:56 +03:00
|
|
|
|
|
|
|
// Globals
|
2023-11-14 18:01:52 +03:00
|
|
|
Fl_Terminal *G_tty = 0;
|
2005-02-25 00:14:22 +03:00
|
|
|
|
2024-06-27 04:19:26 +03:00
|
|
|
void active_cb(Fl_Widget *w, void *data) {
|
|
|
|
Fl_Check_Button *b = (Fl_Check_Button *)w;
|
|
|
|
Fl_Group *g = (Fl_Group *)data;
|
|
|
|
if (b->value()) {
|
|
|
|
g->activate();
|
|
|
|
G_tty->printf("activate group\n");
|
|
|
|
} else {
|
|
|
|
g->deactivate();
|
|
|
|
G_tty->printf("deactivate group\n");
|
|
|
|
}
|
|
|
|
g->redraw();
|
|
|
|
if (b->changed()) {
|
|
|
|
G_tty->printf("Callback: changed() is set\n");
|
|
|
|
b->clear_changed();
|
|
|
|
}
|
2005-02-25 00:14:22 +03:00
|
|
|
}
|
|
|
|
|
2024-06-27 04:19:26 +03:00
|
|
|
void input_choice_cb(Fl_Widget *, void *data) {
|
|
|
|
Fl_Input_Choice *in = (Fl_Input_Choice *)data;
|
|
|
|
G_tty->printf("Fl_Input_Choice value='%s'\n", (const char *)in->value());
|
|
|
|
}
|
|
|
|
|
|
|
|
void choice_cb(Fl_Widget *, void *data) {
|
|
|
|
Fl_Choice *in = (Fl_Choice *)data;
|
|
|
|
G_tty->printf("Fl_Choice value='%d'\n", in->value());
|
2005-02-25 00:14:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2024-06-27 04:19:26 +03:00
|
|
|
Fl_Window *win = new Fl_Double_Window(300, 200 + TERMINAL_HEIGHT);
|
|
|
|
|
|
|
|
G_tty = new Fl_Terminal(0, 200, win->w(), TERMINAL_HEIGHT);
|
|
|
|
|
|
|
|
// this group can be activated and deactivated:
|
|
|
|
Fl_Group *active_group = new Fl_Group(0, 0, 300, 120);
|
|
|
|
|
|
|
|
// all *_Choice widgets must be aligned for easier visual comparison:
|
|
|
|
|
|
|
|
Fl_Input_Choice *in = new Fl_Input_Choice(180, 40, 100, 25, "Fl_Input_Choice:");
|
|
|
|
in->callback(input_choice_cb, (void *)in);
|
|
|
|
in->add("one");
|
|
|
|
in->add("two");
|
|
|
|
in->add("three");
|
|
|
|
in->value(0);
|
|
|
|
|
|
|
|
Fl_Choice *choice = new Fl_Choice(180, 70, 100, 25, "Fl_Choice:");
|
|
|
|
choice->callback(choice_cb, (void *)choice);
|
|
|
|
choice->add("aaa");
|
|
|
|
choice->add("bbb");
|
|
|
|
choice->add("ccc");
|
|
|
|
choice->value(1);
|
|
|
|
|
|
|
|
active_group->end();
|
|
|
|
|
|
|
|
// Interactive control of scheme
|
|
|
|
Fl_Scheme_Choice *sch = new Fl_Scheme_Choice(180, 120, 100, 25, "Choose scheme:");
|
|
|
|
sch->visible_focus(0);
|
|
|
|
|
|
|
|
Fl_Check_Button *active = new Fl_Check_Button(50, 160, 160, 30, "Activate/deactivate");
|
|
|
|
active->callback(active_cb, (void *)active_group);
|
|
|
|
active->value(1);
|
|
|
|
|
|
|
|
win->end();
|
|
|
|
win->resizable(win);
|
|
|
|
win->size_range(200, 160);
|
|
|
|
win->show(argc, argv);
|
|
|
|
Fl::run();
|
|
|
|
delete win;
|
|
|
|
return 0;
|
2005-02-25 00:14:22 +03:00
|
|
|
}
|