source: rtems-graphics-toolkit/fltk-1.3.0/test/ask.cxx @ 855379e

Last change on this file since 855379e was f5c9e9c, checked in by Alexandru-Sever Horin <alex.sever.h@…>, on 07/05/12 at 09:33:03

Aded FLTK 1.3.0

  • Property mode set to 100644
File size: 3.1 KB
Line 
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
35#include <stdio.h>
36#include <string.h>
37#include <FL/Fl.H>
38#include <FL/Fl_Double_Window.H>
39#include <FL/Fl_Input.H>
40#include <FL/Fl_Button.H>
41#include <FL/Fl_Return_Button.H>
42
43#include <FL/fl_ask.H>
44#include <stdlib.h>
45
46void update_input_text(Fl_Widget* o, const char *input) {
47  if (input) {
48    o->copy_label(input);
49    o->redraw();
50  }
51}
52
53void rename_me(Fl_Widget*o) {
54  const char *input = fl_input("Input:", o->label());
55  update_input_text(o, input);
56}
57
58void rename_me_pwd(Fl_Widget*o) {
59  const char *input = fl_password("Input PWD:", o->label());
60  update_input_text(o, input);
61}
62
63void window_callback(Fl_Widget*, void*) {
64  int hotspot = fl_message_hotspot();
65  fl_message_hotspot(0);
66  fl_message_title("note: no hotspot set for this dialog");
67  int rep = fl_choice("Are you sure you want to quit?",
68                      "Cancel", "Quit", "Dunno");
69  fl_message_hotspot(hotspot);
70  if (rep==1)
71    exit(0);
72  else if (rep==2)
73    fl_message("Well, maybe you should know before we quit.");
74}
75
76int main(int argc, char **argv) {
77  char buffer[128] = "Test text";
78  char buffer2[128] = "MyPassword";
79
80// this is a test to make sure automatic destructors work.  Pop up
81// the question dialog several times and make sure it doesn't crash.
82// fc: added more fl_ask common dialogs for test cases purposes.
83
84  Fl_Double_Window window(200, 105);
85  Fl_Return_Button b(20, 10, 160, 35, buffer); b.callback(rename_me);
86  Fl_Button b2(20, 50, 160, 35, buffer2); b2.callback(rename_me_pwd);
87  window.end();
88  window.resizable(&b);
89  window.show(argc, argv);
90
91// Also we test to see if the exit callback works:
92  window.callback(window_callback);
93
94// set default message window title
95  // fl_message_title_default("Default Window Title");
96
97  return Fl::run();
98}
99   
100//
101// End of "$Id: ask.cxx 8441 2011-02-18 08:52:48Z AlbrechtS $".
102//
Note: See TracBrowser for help on using the repository browser.