summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2025-04-03 11:23:57 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2025-04-03 11:23:57 +0200
commit71caca84d92161792861fb33381f7a9c2be05343 (patch)
tree0a9bd0ef23ba4051af4070dba1afcf87111ec7b6 /test
parent07bb343de7c6b4152a7eb8940da99d5d006f27cd (diff)
parent678c85027294c0ae5162d02b20a59fde758ac77a (diff)
Merge remote-tracking branch 'refs/remotes/origin/master'
Diffstat (limited to 'test')
-rw-r--r--test/color_chooser.cxx28
-rw-r--r--test/fractals.cxx2
-rw-r--r--test/menubar.cxx47
-rw-r--r--test/terminal.fl10
4 files changed, 76 insertions, 11 deletions
diff --git a/test/color_chooser.cxx b/test/color_chooser.cxx
index 61fbc4caf..263cad28a 100644
--- a/test/color_chooser.cxx
+++ b/test/color_chooser.cxx
@@ -21,6 +21,7 @@
#include <FL/fl_show_colormap.H>
#include <FL/Fl_Color_Chooser.H>
#include <FL/Fl_Image.H>
+#include <FL/Fl_Tooltip.H>
#include <FL/platform.H>
#include <FL/fl_draw.H>
@@ -84,10 +85,35 @@ void cb2(Fl_Widget *, void *v) {
bx->parent()->redraw();
}
+class Sample_Box: public Fl_Box {
+public:
+ Sample_Box(int x, int y, int w, int h, const char *label = nullptr)
+ : Fl_Box(x, y, w, h, label) { }
+ int handle(int event) override {
+ if (event == FL_BEFORE_TOOLTIP) {
+ char buf[128];
+ uchar r, g, b;
+ Fl::get_color(color(), r, g, b);
+ if ((color()&255) && (color()!=16)) {
+ ::snprintf(buf, 127,
+ "Background color is:\n"
+ "palette no. %d = r:%d, g:%d, b:%d", color(), r, g, b);
+ } else {
+ ::snprintf(buf, 127,
+ "Background color is:\n"
+ "r:%d, g:%d, b:%d", r, g, b);
+ }
+ return Fl_Tooltip::override_text(buf);
+ }
+ return Fl_Box::handle(event);
+ }
+};
+
int main(int argc, char ** argv) {
Fl::set_color(fullcolor_cell,145,159,170);
Fl_Window window(400,400);
- Fl_Box box(30,30,340,340);
+ Sample_Box box(30,30,340,340);
+ box.tooltip("Show RGB values");
box.box(FL_THIN_DOWN_BOX);
c = fullcolor_cell;
box.color(c);
diff --git a/test/fractals.cxx b/test/fractals.cxx
index d9cf9905f..5e3839d03 100644
--- a/test/fractals.cxx
+++ b/test/fractals.cxx
@@ -70,7 +70,7 @@ int main(int, char**) {
# define srand48(x) (srand((x)))
#elif defined __APPLE__
# define drand48() (((float) rand())/((float) RAND_MAX))
-# define srand48(x) (srand((x)))
+# define srand48(x) (srand((int)(x)))
#endif
typedef enum { NOTALLOWED, MOUNTAIN, TREE, ISLAND, BIGMTN, STEM, LEAF,
diff --git a/test/menubar.cxx b/test/menubar.cxx
index a5ccfc234..355921eba 100644
--- a/test/menubar.cxx
+++ b/test/menubar.cxx
@@ -61,7 +61,19 @@ void test_cb(Fl_Widget* w, void*) {
G_tty->printf("%s\n", m->label());
}
-void quit_cb(Fl_Widget*, void*) {exit(0);}
+void quit_cb(Fl_Widget*, void*) {
+ switch (Fl::callback_reason()) {
+ case FL_REASON_SELECTED:
+ exit(0);
+ case FL_REASON_GOT_FOCUS:
+ G_tty->printf("Selecting this menu item will quit this application!\n");
+ break;
+ case FL_REASON_LOST_FOCUS:
+ G_tty->printf("Risk of quitting averted.\n");
+ break;
+ default: break;
+ }
+}
Fl_Menu_Item hugemenu[100];
@@ -70,7 +82,7 @@ Fl_Menu_Item menutable[] = {
{"&File",0,0,0,FL_SUBMENU},
{"&Open", FL_ALT+'o', 0, 0, FL_MENU_INACTIVE},
{"&Close", 0, 0},
- {"&Quit", FL_ALT+'q', quit_cb, 0, FL_MENU_DIVIDER},
+ {"&Quit", FL_ALT+'q', quit_cb, 0, FL_MENU_DIVIDER|FL_MENU_CHATTY},
#if (OVERRIDE_SCALING_SHORTCUTS)
{"CTRL/0", FL_COMMAND+'0', 0},
@@ -210,7 +222,7 @@ void menu_location_cb(Fl_Widget* w, void* data)
if (((Fl_Choice*)w)->value() == 1) { // switch to system menu bar
menubar->hide();
const Fl_Menu_Item *menu = menubar->menu();
- smenubar = new Fl_Sys_Menu_Bar(0,0,0,30);
+ smenubar = new Fl_Sys_Menu_Bar(0,0,0,30);
smenubar->menu(menu);
smenubar->callback(test_cb);
}
@@ -236,6 +248,30 @@ void about_cb(Fl_Widget*, void*) {
fl_message("The menubar test app.");
}
+class Dynamic_Choice: public Fl_Choice {
+public:
+ Dynamic_Choice(int x, int y, int w, int h, const char *label=nullptr)
+ : Fl_Choice(x, y, w, h, label) { }
+ int handle(int event) override {
+ static int flip_flop = 0;
+ if (event == FL_BEFORE_MENU) {
+ // The following line is legal because we used `copy()` to create a
+ // writable copy of the menu array when creating this Choice.
+ Fl_Menu_Item *mi = const_cast<Fl_Menu_Item*>(menu());
+ if (flip_flop == 1) {
+ mi[7].flags |= FL_MENU_INACTIVE;
+ mi[8].flags &= ~FL_MENU_INACTIVE;
+ flip_flop = 0;
+ } else {
+ mi[7].flags &= ~FL_MENU_INACTIVE;
+ mi[8].flags |= FL_MENU_INACTIVE;
+ flip_flop = 1;
+ }
+ }
+ return Fl_Choice::handle(event);
+ }
+};
+
int main(int argc, char **argv) {
for (int i=0; i<99; i++) {
char buf[100];
@@ -256,7 +292,10 @@ int main(int argc, char **argv) {
mb1.tooltip("this is a menu button");
mb1.callback(test_cb);
menus[1] = &mb1;
- Fl_Choice ch(300,100,80,25,"&choice:"); ch.menu(pulldown);
+ Dynamic_Choice ch(300,100,80,25,"&choice:");
+ ch.copy(pulldown);
+ ch.add("Flip");
+ ch.add("Flop");
ch.tooltip("this is a choice menu");
ch.callback(test_cb);
menus[2] = &ch;
diff --git a/test/terminal.fl b/test/terminal.fl
index b2c0d4d1f..3c9186b68 100644
--- a/test/terminal.fl
+++ b/test/terminal.fl
@@ -452,8 +452,7 @@ const char *test[] = {
};
if (reset) { index = 0; return 0; }
-return show_test(test, index);} {selected
- }
+return show_test(test, index);} {}
}
Function {test_esc_rgbcolors(bool reset)} {
comment {--- 0020: Test RGB Colors} return_type {static int}
@@ -1373,7 +1372,7 @@ for ( int t=0; t<count; t++ )
}
Function {do_command(const char *cmd)} {
comment {Run the command, output appends to terminal
-} return_type void
+} open return_type void
} {
code {// Run command in pipe, return output to tty
// TODO: This should probably be reimplemented as a thread.
@@ -1420,13 +1419,14 @@ while (1) {
Fl::wait(0.05);
SSIZE_T bytes = READ(fd, s, sizeof(s)); // shout in uppercase so windows can hear us
if (bytes == -1 && errno == EAGAIN) continue; // no data yet
- else if (bytes > 0) G_tty->append(s, bytes); // write block to terminal, handles utf8
+ else if (bytes > 0) G_tty->append(s, (int)bytes); // write block to terminal, handles utf8
else break; // pipe closed
}
PCLOSE(fp);
G_tty->append_ascii("\\033[33;2m<<END_OF_OUTPUT>>\\033[0m\\n");
-G_tty->redraw();} {}
+G_tty->redraw();} {selected
+ }
}
decl {////// GUI LAYOUT //////} {private local
}