source: rtems-graphics-toolkit/fltk-1.3.0/test/input.cxx

Last change on this file was a2d9dfc, checked in by Alexandru-Sever Horin <alex.sever.h@…>, on 08/09/12 at 13:11:37

Modified tests to use a wrapper file(function) on linkage

  • Property mode set to 100644
File size: 6.0 KB
Line 
1//
2// "$Id: input.cxx 8419 2011-02-13 16:13:04Z greg.ercolano $"
3//
4// Input field test program for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2010 by Bill Spitzak and others.
7//
8// This library is free software; you can redistribute it and/or
9// modify it under the terms of the GNU Library General Public
10// License as published by the Free Software Foundation; either
11// version 2 of the License, or (at your option) any later version.
12//
13// This library is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16// Library General Public License for more details.
17//
18// You should have received a copy of the GNU Library General Public
19// License along with this library; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25//     http://www.fltk.org/str.php
26//
27
28#include <stdio.h>
29#include <FL/Fl.H>
30#include <FL/Fl_Window.H>
31#include <FL/Fl_Input.H>
32#include <FL/Fl_Float_Input.H>
33#include <FL/Fl_Int_Input.H>
34#include <FL/Fl_Secret_Input.H>
35#include <FL/Fl_Multiline_Input.H>
36#include <FL/Fl_Button.H>
37#include <FL/Fl_Toggle_Button.H>
38#include <FL/Fl_Light_Button.H>
39#include <FL/Fl_Color_Chooser.H>
40
41void cb(Fl_Widget *ob) {
42  printf("Callback for %s '%s'\n",ob->label(),((Fl_Input*)ob)->value());
43}
44
45int when = 0;
46Fl_Input *input[5];
47
48void toggle_cb(Fl_Widget *o, long v) {
49  if (((Fl_Toggle_Button*)o)->value()) when |= v; else when &= ~v;
50  for (int i=0; i<5; i++) input[i]->when(when);
51}
52
53void test(Fl_Input *i) {
54  if (i->changed()) {
55    i->clear_changed(); printf("%s '%s'\n",i->label(),i->value());
56    char utf8buf[10];
57    int last = fl_utf8encode(i->index(i->position()), utf8buf);
58    utf8buf[last] = 0;
59    printf("Symbol at cursor position: %s\n", utf8buf);
60  }
61}
62
63void button_cb(Fl_Widget *,void *) {
64  for (int i=0; i<5; i++) test(input[i]);
65}
66
67void color_cb(Fl_Widget* button, void* v) {
68  Fl_Color c;
69  switch ((fl_intptr_t)v) {
70  case 0: c = FL_BACKGROUND2_COLOR; break;
71  case 1: c = FL_SELECTION_COLOR; break;
72  default: c = FL_FOREGROUND_COLOR; break;
73  }
74  uchar r,g,b; Fl::get_color(c, r,g,b);
75  if (fl_color_chooser(0,r,g,b)) {
76    Fl::set_color(c,r,g,b); Fl::redraw();
77    button->labelcolor(fl_contrast(FL_BLACK,c));
78    button->redraw();
79  }
80}
81
82void tabnav_cb(Fl_Widget *w, void *v) {
83  Fl_Light_Button *b = (Fl_Light_Button*)w;
84  Fl_Multiline_Input *fmi = (Fl_Multiline_Input*)v;
85  fmi->tab_nav(b->value() ? 1 : 0);
86}
87
88void arrownav_cb(Fl_Widget *w, void *v) {
89  Fl_Light_Button *b = (Fl_Light_Button*)w;
90  Fl::option(Fl::OPTION_ARROW_FOCUS, b->value() ? true : false);
91}
92
93int main(int argc, char **argv) {
94  // the following two lines set the correct color scheme, so that
95  // calling fl_contrast below will return good results
96  Fl::args(argc, argv);
97  Fl::get_system_colors();
98  Fl_Window *window = new Fl_Window(400,420);
99
100  int y = 10;
101  input[0] = new Fl_Input(70,y,300,30,"Normal:"); y += 35;
102  input[0]->tooltip("Normal input field");
103  // input[0]->cursor_color(FL_SELECTION_COLOR);
104  // input[0]->maximum_size(20);
105  // input[0]->static_value("this is a testgarbage");
106  input[1] = new Fl_Float_Input(70,y,300,30,"Float:"); y += 35;
107  input[1]->tooltip("Input field for floating-point number (F1)");
108  input[1]->shortcut(FL_F+1);
109  input[2] = new Fl_Int_Input(70,y,300,30,"Int:"); y += 35;
110  input[2]->tooltip("Input field for integer number (F2)");
111  input[2]->shortcut(FL_F+2);
112  input[3] = new Fl_Secret_Input(70,y,300,30,"&Secret:"); y += 35;
113  input[3]->tooltip("Input field for password (Alt-S)");
114  input[4] = new Fl_Multiline_Input(70,y,300,100,"&Multiline:"); y += 105;
115  input[4]->tooltip("Input field for short text with newlines (Alt-M)");
116  input[4]->wrap(1);
117
118  for (int i = 0; i < 4; i++) {
119    input[i]->when(0); input[i]->callback(cb);
120  }
121  int y1 = y;
122
123  Fl_Button *b;
124  b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_CHANGED");
125  b->callback(toggle_cb, FL_WHEN_CHANGED); y += 25;
126  b->tooltip("Do callback each time the text changes");
127  b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_RELEASE");
128  b->callback(toggle_cb, FL_WHEN_RELEASE); y += 25;
129  b->tooltip("Do callback when widget loses focus");
130  b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_ENTER_KEY");
131  b->callback(toggle_cb, FL_WHEN_ENTER_KEY); y += 25;
132  b->tooltip("Do callback when user hits Enter key");
133  b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_NOT_CHANGED");
134  b->callback(toggle_cb, FL_WHEN_NOT_CHANGED); y += 25;
135  b->tooltip("Do callback even if the text is not changed");
136  y += 5;
137  b = new Fl_Button(10,y,200,25,"&print changed()"); y += 25;
138  b->callback(button_cb);
139  b->tooltip("Print widgets that have changed() flag set");
140
141  b = new Fl_Light_Button(10,y,100,25," Tab Nav");
142  b->tooltip("Control tab navigation for the multiline input field");
143  b->callback(tabnav_cb, (void*)input[4]);
144  b->value(input[4]->tab_nav() ? 1 : 0);
145  b = new Fl_Light_Button(110,y,100,25," Arrow Nav"); y += 25;
146  b->tooltip("Control horizontal arrow key focus navigation behavior.\n"
147             "e.g. Fl::OPTION_ARROW_FOCUS");
148  b->callback(arrownav_cb);
149  b->value(input[4]->tab_nav() ? 1 : 0);
150  b->value(Fl::option(Fl::OPTION_ARROW_FOCUS) ? 1 : 0);
151
152  b = new Fl_Button(220,y1,120,25,"color"); y1 += 25;
153  b->color(input[0]->color()); b->callback(color_cb, (void*)0);
154  b->tooltip("Color behind the text");
155  b = new Fl_Button(220,y1,120,25,"selection_color"); y1 += 25;
156  b->color(input[0]->selection_color()); b->callback(color_cb, (void*)1);
157  b->labelcolor(fl_contrast(FL_BLACK,b->color()));
158  b->tooltip("Color behind selected text");
159  b = new Fl_Button(220,y1,120,25,"textcolor"); y1 += 25;
160  b->color(input[0]->textcolor()); b->callback(color_cb, (void*)2);
161  b->labelcolor(fl_contrast(FL_BLACK,b->color()));
162  b->tooltip("Color of the text");
163
164  window->end();
165  window->show(argc,argv);
166  return Fl::run();
167}
168
169//
170// End of "$Id: input.cxx 8419 2011-02-13 16:13:04Z greg.ercolano $".
171//
Note: See TracBrowser for help on using the repository browser.