You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.1KB

  1. //
  2. // "$Id: ask.cxx 8441 2011-02-18 08:52:48Z AlbrechtS $"
  3. //
  4. // Standard dialog test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Demonstrates how to use readqueue to see if a button has been
  7. // pushed, and to see if a window has been closed, thus avoiding
  8. // the need to define callbacks.
  9. //
  10. // This also demonstrates how to trap attempts by the user to
  11. // close the last window by overriding Fl::exit
  12. //
  13. // Copyright 1998-2010 by Bill Spitzak and others.
  14. //
  15. // This library is free software; you can redistribute it and/or
  16. // modify it under the terms of the GNU Library General Public
  17. // License as published by the Free Software Foundation; either
  18. // version 2 of the License, or (at your option) any later version.
  19. //
  20. // This library is distributed in the hope that it will be useful,
  21. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. // Library General Public License for more details.
  24. //
  25. // You should have received a copy of the GNU Library General Public
  26. // License along with this library; if not, write to the Free Software
  27. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  28. // USA.
  29. //
  30. // Please report all bugs and problems on the following page:
  31. //
  32. // http://www.fltk.org/str.php
  33. //
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <FL/Fl.H>
  37. #include <FL/Fl_Double_Window.H>
  38. #include <FL/Fl_Input.H>
  39. #include <FL/Fl_Button.H>
  40. #include <FL/Fl_Return_Button.H>
  41. #include <FL/fl_ask.H>
  42. #include <stdlib.h>
  43. void update_input_text(Fl_Widget* o, const char *input) {
  44. if (input) {
  45. o->copy_label(input);
  46. o->redraw();
  47. }
  48. }
  49. void rename_me(Fl_Widget*o) {
  50. const char *input = fl_input("Input:", o->label());
  51. update_input_text(o, input);
  52. }
  53. void rename_me_pwd(Fl_Widget*o) {
  54. const char *input = fl_password("Input PWD:", o->label());
  55. update_input_text(o, input);
  56. }
  57. void window_callback(Fl_Widget*, void*) {
  58. int hotspot = fl_message_hotspot();
  59. fl_message_hotspot(0);
  60. fl_message_title("note: no hotspot set for this dialog");
  61. int rep = fl_choice("Are you sure you want to quit?",
  62. "Cancel", "Quit", "Dunno");
  63. fl_message_hotspot(hotspot);
  64. if (rep==1)
  65. exit(0);
  66. else if (rep==2)
  67. fl_message("Well, maybe you should know before we quit.");
  68. }
  69. int main(int argc, char **argv) {
  70. char buffer[128] = "Test text";
  71. char buffer2[128] = "MyPassword";
  72. // this is a test to make sure automatic destructors work. Pop up
  73. // the question dialog several times and make sure it doesn't crash.
  74. // fc: added more fl_ask common dialogs for test cases purposes.
  75. Fl_Double_Window window(200, 105);
  76. Fl_Return_Button b(20, 10, 160, 35, buffer); b.callback(rename_me);
  77. Fl_Button b2(20, 50, 160, 35, buffer2); b2.callback(rename_me_pwd);
  78. window.end();
  79. window.resizable(&b);
  80. window.show(argc, argv);
  81. // Also we test to see if the exit callback works:
  82. window.callback(window_callback);
  83. // set default message window title
  84. // fl_message_title_default("Default Window Title");
  85. return Fl::run();
  86. }
  87. //
  88. // End of "$Id: ask.cxx 8441 2011-02-18 08:52:48Z AlbrechtS $".
  89. //