summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2021-12-04 13:35:47 +0100
committerAlbrecht Schlosser <albrechts.fltk@online.de>2021-12-04 14:49:27 +0100
commitb6de09cff2465db3c0a6e6a013b825462bc9a0e7 (patch)
tree23725f27cc08e314f3c5d15d1c47c3f3b24b7588 /test
parent240465626604ed9a7f7b2cb997ab4dffd419eabc (diff)
Re-enable nested (aka recursive) common dialogs (STR 3242, #282)
Apply Fl_Dialog_r10831.patch as given in STR 3242: https://www.fltk.org/strfiles/3242/Fl_Dialog_r10831.patch Reformat, add missing pieces, rename private members, cleanup... Improve documentation, add fl_choice_n() (issue #282) New methods fl_input_str() and fl_password_str() return Fl_String
Diffstat (limited to 'test')
-rw-r--r--test/ask.cxx99
-rw-r--r--test/makedepend26
2 files changed, 81 insertions, 44 deletions
diff --git a/test/ask.cxx b/test/ask.cxx
index a3caea0ab..0800f2d01 100644
--- a/test/ask.cxx
+++ b/test/ask.cxx
@@ -4,7 +4,7 @@
// This also demonstrates how to trap attempts by the user to
// close the last window by overriding Fl::exit
//
-// Copyright 1998-2017 by Bill Spitzak and others.
+// Copyright 1998-2021 by Bill Spitzak and others.
//
// 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
@@ -17,10 +17,6 @@
// https://www.fltk.org/bugs.php
//
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
#include <FL/Fl.H>
#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Input.H>
@@ -30,33 +26,34 @@
#include <FL/fl_ask.H>
-void update_input_text(Fl_Widget* o, const char *input) {
- if (input) {
- o->copy_label(input);
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+// Button callback: v == 0 ("input") or 1 ("password")
+
+void rename_button(Fl_Widget *o, void *v) {
+ int what = fl_int(v);
+ Fl_String input;
+ if (what == 0)
+ input = fl_input_str(0, "Input (no size limit, use ctrl/j for newline):", o->label());
+ else
+ input = fl_password_str(20, "Enter password (max. 20 characters):", o->label());
+ if (input.value()) {
+ o->copy_label(input.value());
o->redraw();
}
}
-void rename_me(Fl_Widget*o) {
- const char *input = fl_input("Input:", o->label());
- update_input_text(o, input);
-}
-
-void rename_me_pwd(Fl_Widget*o) {
- const char *input = fl_password("Input PWD:", o->label());
- update_input_text(o, input);
-}
-
-void window_callback(Fl_Widget *win, void*) {
+void window_callback(Fl_Widget *win, void *) {
int hotspot = fl_message_hotspot();
fl_message_hotspot(0);
fl_message_title("note: no hotspot set for this dialog");
- int rep = fl_choice("Are you sure you want to quit?",
- "Cancel", "Quit", "Dunno");
+ int rep = fl_choice("Are you sure you want to quit?", "Cancel", "Quit", "Dunno");
fl_message_hotspot(hotspot);
- if (rep==1)
+ if (rep == 1)
exit(0);
- else if (rep==2) { // (Dunno)
+ else if (rep == 2) { // (Dunno)
fl_message_position(win);
fl_message_title("This dialog must be centered over the main window");
fl_message("Well, maybe you should know before we quit.");
@@ -65,45 +62,61 @@ void window_callback(Fl_Widget *win, void*) {
/*
This timer callback shows a message dialog (fl_choice) window
- every 5 seconds to test "recursive" common dialogs.
+ every 5 seconds to test "recursive" (aka nested) common dialogs.
The timer can be stopped by clicking the button "Stop these funny popups"
or pressing the Enter key. As it is currently implemented, clicking the
"Close" button will reactivate the popups (only possible if "recursive"
dialogs are enabled, see below).
- Note 1: This dialog box is blocked in FLTK 1.3.x if another common dialog
- is already open because the window used is a static (i.e. permanently
- allocated) Fl_Window instance. This should be fixed in FLTK 1.4.0.
+ Note 1: This dialog box had been blocked in FLTK 1.3.x if another common
+ dialog was already open because the window used was a static (i.e. permanently
+ allocated) Fl_Window instance. This has been fixed in FLTK 1.4.0.
See STR #334 (sic !) and also STR #2751 ("Limit input field characters").
*/
void timer_cb(void *) {
static int stop = 0;
- static const double delta = 5.0;
+ static int n = 0;
+ const double delta = 5.0; // delay of popups
+ const int nmax = 10; // limit no. of popups
+ n++;
+ if (n >= nmax)
+ stop = 1;
Fl_Box *message_icon = (Fl_Box *)fl_message_icon();
- Fl::repeat_timeout(delta, timer_cb);
-
- if (stop == 1) {
+ if (stop) {
message_icon->color(FL_WHITE);
return;
}
+ Fl::repeat_timeout(delta, timer_cb);
+
// Change the icon box color:
Fl_Color c = message_icon->color();
- c = (c+1) % 32;
- if (c == message_icon->labelcolor()) c++;
+ c = (c + 1) % 32;
+ if (c == message_icon->labelcolor())
+ c++;
message_icon->color((Fl_Color)c);
+ // test message title assignment with a local buffer
+ { // local scope for buf
+ char buf[40]; // test: use local variable
+ sprintf(buf, "Message #%d", n); // fill message title
+ fl_message_title(buf); // set message title
+ strcpy(buf, "** void **"); // overwrite buffer to be sure
+ } // buf goes out of scope here
+
// pop up a message:
- stop = fl_choice("Timeout. Click the 'Close' button.\n"
- "Note: this message was blocked in FLTK 1.3\n"
- "if another message window is open.\n"
- "This *should* be fixed in FLTK 1.4.0!\n"
- "This message should pop up every 5 seconds.",
- "Close", "Stop these funny popups", NULL);
+ stop |= fl_choice(
+ "Timeout. Click the 'Close' button or press Escape.\n"
+ "Note: this message had been blocked in FLTK 1.3.x\n"
+ "and earlier if another message window was open.\n"
+ "This message should pop up every 5 seconds (max. 10 times)\n"
+ "in FLTK 1.4.0 and later until stopped by clicking the button\n"
+ "below or by pressing the Enter (Return) key.\n",
+ "Close", "Stop these funny popups", NULL);
}
int main(int argc, char **argv) {
@@ -115,9 +128,9 @@ int main(int argc, char **argv) {
Fl_Double_Window window(200, 105);
Fl_Return_Button b(20, 10, 160, 35, buffer);
- b.callback(rename_me);
+ b.callback(rename_button, (void *)(0));
Fl_Button b2(20, 50, 160, 35, buffer2);
- b2.callback(rename_me_pwd);
+ b2.callback(rename_button, (void *)(1));
window.end();
window.resizable(&b);
window.show(argc, argv);
@@ -126,9 +139,9 @@ int main(int argc, char **argv) {
window.callback(window_callback);
// Test: set default message window title:
- // fl_message_title_default("Default Window Title");
+ // fl_message_title_default("Default Message Title");
- // Test: multiple (nested, aka "recursive") popups
+ // Test: multiple (nested, aka "recursive") popups (see timer_cb())
Fl::add_timeout(5.0, timer_cb);
return Fl::run();
diff --git a/test/makedepend b/test/makedepend
index f36d983f0..4f4e5e76d 100644
--- a/test/makedepend
+++ b/test/makedepend
@@ -83,6 +83,7 @@ ask.o: ../FL/Fl_Image.H
ask.o: ../FL/Fl_Input.H
ask.o: ../FL/Fl_Input_.H
ask.o: ../FL/Fl_Return_Button.H
+ask.o: ../FL/Fl_String.H
ask.o: ../FL/fl_types.h
ask.o: ../FL/fl_utf8.h
ask.o: ../FL/Fl_Widget.H
@@ -203,6 +204,7 @@ browser.o: ../FL/Fl_Scrollbar.H
browser.o: ../FL/Fl_Select_Browser.H
browser.o: ../FL/Fl_Simple_Terminal.H
browser.o: ../FL/Fl_Slider.H
+browser.o: ../FL/Fl_String.H
browser.o: ../FL/Fl_Text_Buffer.H
browser.o: ../FL/Fl_Text_Display.H
browser.o: ../FL/fl_types.h
@@ -222,6 +224,7 @@ button.o: ../FL/fl_casts.H
button.o: ../FL/Fl_Export.H
button.o: ../FL/Fl_Group.H
button.o: ../FL/Fl_Image.H
+button.o: ../FL/Fl_String.H
button.o: ../FL/fl_types.h
button.o: ../FL/fl_utf8.h
button.o: ../FL/Fl_Widget.H
@@ -297,6 +300,7 @@ checkers.o: ../FL/Fl_Preferences.H
checkers.o: ../FL/Fl_Rect.H
checkers.o: ../FL/Fl_RGB_Image.H
checkers.o: ../FL/Fl_Slider.H
+checkers.o: ../FL/Fl_String.H
checkers.o: ../FL/fl_types.h
checkers.o: ../FL/fl_utf8.h
checkers.o: ../FL/Fl_Valuator.H
@@ -347,6 +351,7 @@ clipboard.o: ../FL/Fl_RGB_Image.H
clipboard.o: ../FL/Fl_Scrollbar.H
clipboard.o: ../FL/Fl_Shared_Image.H
clipboard.o: ../FL/Fl_Slider.H
+clipboard.o: ../FL/Fl_String.H
clipboard.o: ../FL/Fl_Tabs.H
clipboard.o: ../FL/Fl_Text_Buffer.H
clipboard.o: ../FL/Fl_Text_Display.H
@@ -392,6 +397,7 @@ colbrowser.o: ../FL/Fl_Hold_Browser.H
colbrowser.o: ../FL/Fl_Image.H
colbrowser.o: ../FL/Fl_Scrollbar.H
colbrowser.o: ../FL/Fl_Slider.H
+colbrowser.o: ../FL/Fl_String.H
colbrowser.o: ../FL/fl_types.h
colbrowser.o: ../FL/fl_utf8.h
colbrowser.o: ../FL/Fl_Valuator.H
@@ -595,6 +601,7 @@ demo.o: ../FL/Fl_RGB_Image.H
demo.o: ../FL/Fl_Scrollbar.H
demo.o: ../FL/Fl_Simple_Terminal.H
demo.o: ../FL/Fl_Slider.H
+demo.o: ../FL/Fl_String.H
demo.o: ../FL/Fl_Text_Buffer.H
demo.o: ../FL/Fl_Text_Display.H
demo.o: ../FL/fl_types.h
@@ -653,6 +660,7 @@ device.o: ../FL/Fl_Round_Button.H
device.o: ../FL/Fl_Scrollbar.H
device.o: ../FL/Fl_Shared_Image.H
device.o: ../FL/Fl_Slider.H
+device.o: ../FL/Fl_String.H
device.o: ../FL/Fl_SVG_File_Surface.H
device.o: ../FL/Fl_Tile.H
device.o: ../FL/fl_types.h
@@ -733,6 +741,7 @@ editor.o: ../FL/Fl_Return_Button.H
editor.o: ../FL/Fl_RGB_Image.H
editor.o: ../FL/Fl_Scrollbar.H
editor.o: ../FL/Fl_Slider.H
+editor.o: ../FL/Fl_String.H
editor.o: ../FL/Fl_Text_Buffer.H
editor.o: ../FL/Fl_Text_Display.H
editor.o: ../FL/Fl_Text_Editor.H
@@ -804,6 +813,7 @@ file_chooser.o: ../FL/Fl_Scrollbar.H
file_chooser.o: ../FL/Fl_Shared_Image.H
file_chooser.o: ../FL/Fl_Simple_Terminal.H
file_chooser.o: ../FL/Fl_Slider.H
+file_chooser.o: ../FL/Fl_String.H
file_chooser.o: ../FL/Fl_Text_Buffer.H
file_chooser.o: ../FL/Fl_Text_Display.H
file_chooser.o: ../FL/Fl_Tile.H
@@ -824,6 +834,7 @@ fltk-versions.o: ../FL/fl_casts.H
fltk-versions.o: ../FL/Fl_Export.H
fltk-versions.o: ../FL/Fl_Group.H
fltk-versions.o: ../FL/Fl_Image.H
+fltk-versions.o: ../FL/Fl_String.H
fltk-versions.o: ../FL/fl_types.h
fltk-versions.o: ../FL/fl_utf8.h
fltk-versions.o: ../FL/Fl_Widget.H
@@ -869,6 +880,7 @@ fonts.o: ../FL/Fl_Return_Button.H
fonts.o: ../FL/Fl_RGB_Image.H
fonts.o: ../FL/Fl_Scrollbar.H
fonts.o: ../FL/Fl_Slider.H
+fonts.o: ../FL/Fl_String.H
fonts.o: ../FL/Fl_Tile.H
fonts.o: ../FL/fl_types.h
fonts.o: ../FL/fl_utf8.h
@@ -925,6 +937,7 @@ forms.o: ../FL/Fl_Round_Button.H
forms.o: ../FL/Fl_Scrollbar.H
forms.o: ../FL/fl_show_colormap.H
forms.o: ../FL/Fl_Slider.H
+forms.o: ../FL/Fl_String.H
forms.o: ../FL/Fl_Tile.H
forms.o: ../FL/Fl_Timer.H
forms.o: ../FL/fl_types.h
@@ -1000,6 +1013,7 @@ fullscreen.o: ../FL/Fl_Menu_Item.H
fullscreen.o: ../FL/Fl_Scrollbar.H
fullscreen.o: ../FL/Fl_Single_Window.H
fullscreen.o: ../FL/Fl_Slider.H
+fullscreen.o: ../FL/Fl_String.H
fullscreen.o: ../FL/Fl_Toggle_Light_Button.H
fullscreen.o: ../FL/fl_types.h
fullscreen.o: ../FL/fl_utf8.h
@@ -1416,7 +1430,7 @@ menubar.o: ../FL/Fl_RGB_Image.H
menubar.o: ../FL/Fl_Scrollbar.H
menubar.o: ../FL/Fl_Simple_Terminal.H
menubar.o: ../FL/Fl_Slider.H
-menubar.o: ../FL/fl_string.h
+menubar.o: ../FL/Fl_String.H
menubar.o: ../FL/Fl_Sys_Menu_Bar.H
menubar.o: ../FL/Fl_Text_Buffer.H
menubar.o: ../FL/Fl_Text_Display.H
@@ -1438,6 +1452,7 @@ message.o: ../FL/fl_casts.H
message.o: ../FL/Fl_Export.H
message.o: ../FL/Fl_Group.H
message.o: ../FL/Fl_Image.H
+message.o: ../FL/Fl_String.H
message.o: ../FL/fl_types.h
message.o: ../FL/fl_utf8.h
message.o: ../FL/Fl_Widget.H
@@ -1505,6 +1520,7 @@ native-filechooser.o: ../FL/Fl_RGB_Image.H
native-filechooser.o: ../FL/Fl_Scrollbar.H
native-filechooser.o: ../FL/Fl_Simple_Terminal.H
native-filechooser.o: ../FL/Fl_Slider.H
+native-filechooser.o: ../FL/Fl_String.H
native-filechooser.o: ../FL/Fl_Text_Buffer.H
native-filechooser.o: ../FL/Fl_Text_Display.H
native-filechooser.o: ../FL/Fl_Tile.H
@@ -1693,6 +1709,7 @@ pixmap_browser.o: ../FL/Fl_Return_Button.H
pixmap_browser.o: ../FL/Fl_Scrollbar.H
pixmap_browser.o: ../FL/Fl_Shared_Image.H
pixmap_browser.o: ../FL/Fl_Slider.H
+pixmap_browser.o: ../FL/Fl_String.H
pixmap_browser.o: ../FL/Fl_SVG_File_Surface.H
pixmap_browser.o: ../FL/Fl_Tile.H
pixmap_browser.o: ../FL/fl_types.h
@@ -1727,6 +1744,7 @@ preferences.o: ../FL/Fl_Menu_Item.H
preferences.o: ../FL/Fl_Preferences.H
preferences.o: ../FL/Fl_Round_Button.H
preferences.o: ../FL/Fl_Slider.H
+preferences.o: ../FL/Fl_String.H
preferences.o: ../FL/fl_types.h
preferences.o: ../FL/fl_utf8.h
preferences.o: ../FL/Fl_Valuator.H
@@ -1961,6 +1979,7 @@ resizebox.o: ../FL/Fl_Preferences.H
resizebox.o: ../FL/Fl_Radio_Button.H
resizebox.o: ../FL/Fl_Rect.H
resizebox.o: ../FL/Fl_RGB_Image.H
+resizebox.o: ../FL/Fl_String.H
resizebox.o: ../FL/fl_types.h
resizebox.o: ../FL/fl_utf8.h
resizebox.o: ../FL/Fl_Widget.H
@@ -2107,6 +2126,7 @@ sudoku.o: ../FL/Fl_RGB_Image.H
sudoku.o: ../FL/Fl_Scrollbar.H
sudoku.o: ../FL/Fl_Shared_Image.H
sudoku.o: ../FL/Fl_Slider.H
+sudoku.o: ../FL/Fl_String.H
sudoku.o: ../FL/Fl_Sys_Menu_Bar.H
sudoku.o: ../FL/fl_types.h
sudoku.o: ../FL/fl_utf8.h
@@ -2174,6 +2194,7 @@ table.o: ../FL/Fl_Scroll.H
table.o: ../FL/Fl_Scrollbar.H
table.o: ../FL/Fl_Simple_Terminal.H
table.o: ../FL/Fl_Slider.H
+table.o: ../FL/Fl_String.H
table.o: ../FL/Fl_Table.H
table.o: ../FL/Fl_Table_Row.H
table.o: ../FL/Fl_Text_Buffer.H
@@ -2201,6 +2222,7 @@ tabs.o: ../FL/Fl_Image.H
tabs.o: ../FL/Fl_Input.H
tabs.o: ../FL/Fl_Input_.H
tabs.o: ../FL/Fl_Return_Button.H
+tabs.o: ../FL/Fl_String.H
tabs.o: ../FL/Fl_Tabs.H
tabs.o: ../FL/fl_types.h
tabs.o: ../FL/fl_utf8.h
@@ -2225,6 +2247,7 @@ threads.o: ../FL/Fl_Group.H
threads.o: ../FL/Fl_Image.H
threads.o: ../FL/Fl_Scrollbar.H
threads.o: ../FL/Fl_Slider.H
+threads.o: ../FL/Fl_String.H
threads.o: ../FL/fl_types.h
threads.o: ../FL/fl_utf8.h
threads.o: ../FL/Fl_Valuator.H
@@ -2312,6 +2335,7 @@ tree.o: ../FL/Fl_RGB_Image.H
tree.o: ../FL/Fl_Scrollbar.H
tree.o: ../FL/Fl_Simple_Terminal.H
tree.o: ../FL/Fl_Slider.H
+tree.o: ../FL/Fl_String.H
tree.o: ../FL/Fl_Text_Buffer.H
tree.o: ../FL/Fl_Text_Display.H
tree.o: ../FL/Fl_Tile.H