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

Last change on this file since 855379e was 855379e, checked in by Alexandru-Sever Horin <alex.sever.h@…>, on 08/01/12 at 20:52:27

Added rtems_main.h include to ease migration to RTEMS

  • 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 "rtems_main.h"
29
30#include <stdio.h>
31#include <FL/Fl.H>
32#include <FL/Fl_Window.H>
33#include <FL/Fl_Input.H>
34#include <FL/Fl_Float_Input.H>
35#include <FL/Fl_Int_Input.H>
36#include <FL/Fl_Secret_Input.H>
37#include <FL/Fl_Multiline_Input.H>
38#include <FL/Fl_Button.H>
39#include <FL/Fl_Toggle_Button.H>
40#include <FL/Fl_Light_Button.H>
41#include <FL/Fl_Color_Chooser.H>
42
43void cb(Fl_Widget *ob) {
44  printf("Callback for %s '%s'\n",ob->label(),((Fl_Input*)ob)->value());
45}
46
47int when = 0;
48Fl_Input *input[5];
49
50void toggle_cb(Fl_Widget *o, long v) {
51  if (((Fl_Toggle_Button*)o)->value()) when |= v; else when &= ~v;
52  for (int i=0; i<5; i++) input[i]->when(when);
53}
54
55void test(Fl_Input *i) {
56  if (i->changed()) {
57    i->clear_changed(); printf("%s '%s'\n",i->label(),i->value());
58    char utf8buf[10];
59    int last = fl_utf8encode(i->index(i->position()), utf8buf);
60    utf8buf[last] = 0;
61    printf("Symbol at cursor position: %s\n", utf8buf);
62  }
63}
64
65void button_cb(Fl_Widget *,void *) {
66  for (int i=0; i<5; i++) test(input[i]);
67}
68
69void color_cb(Fl_Widget* button, void* v) {
70  Fl_Color c;
71  switch ((fl_intptr_t)v) {
72  case 0: c = FL_BACKGROUND2_COLOR; break;
73  case 1: c = FL_SELECTION_COLOR; break;
74  default: c = FL_FOREGROUND_COLOR; break;
75  }
76  uchar r,g,b; Fl::get_color(c, r,g,b);
77  if (fl_color_chooser(0,r,g,b)) {
78    Fl::set_color(c,r,g,b); Fl::redraw();
79    button->labelcolor(fl_contrast(FL_BLACK,c));
80    button->redraw();
81  }
82}
83
84void tabnav_cb(Fl_Widget *w, void *v) {
85  Fl_Light_Button *b = (Fl_Light_Button*)w;
86  Fl_Multiline_Input *fmi = (Fl_Multiline_Input*)v;
87  fmi->tab_nav(b->value() ? 1 : 0);
88}
89
90void arrownav_cb(Fl_Widget *w, void *v) {
91  Fl_Light_Button *b = (Fl_Light_Button*)w;
92  Fl::option(Fl::OPTION_ARROW_FOCUS, b->value() ? true : false);
93}
94
95int main(int argc, char **argv) {
96  // the following two lines set the correct color scheme, so that
97  // calling fl_contrast below will return good results
98  Fl::args(argc, argv);
99  Fl::get_system_colors();
100  Fl_Window *window = new Fl_Window(400,420);
101
102  int y = 10;
103  input[0] = new Fl_Input(70,y,300,30,"Normal:"); y += 35;
104  input[0]->tooltip("Normal input field");
105  // input[0]->cursor_color(FL_SELECTION_COLOR);
106  // input[0]->maximum_size(20);
107  // input[0]->static_value("this is a testgarbage");
108  input[1] = new Fl_Float_Input(70,y,300,30,"Float:"); y += 35;
109  input[1]->tooltip("Input field for floating-point number (F1)");
110  input[1]->shortcut(FL_F+1);
111  input[2] = new Fl_Int_Input(70,y,300,30,"Int:"); y += 35;
112  input[2]->tooltip("Input field for integer number (F2)");
113  input[2]->shortcut(FL_F+2);
114  input[3] = new Fl_Secret_Input(70,y,300,30,"&Secret:"); y += 35;
115  input[3]->tooltip("Input field for password (Alt-S)");
116  input[4] = new Fl_Multiline_Input(70,y,300,100,"&Multiline:"); y += 105;
117  input[4]->tooltip("Input field for short text with newlines (Alt-M)");
118  input[4]->wrap(1);
119
120  for (int i = 0; i < 4; i++) {
121    input[i]->when(0); input[i]->callback(cb);
122  }
123  int y1 = y;
124
125  Fl_Button *b;
126  b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_CHANGED");
127  b->callback(toggle_cb, FL_WHEN_CHANGED); y += 25;
128  b->tooltip("Do callback each time the text changes");
129  b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_RELEASE");
130  b->callback(toggle_cb, FL_WHEN_RELEASE); y += 25;
131  b->tooltip("Do callback when widget loses focus");
132  b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_ENTER_KEY");
133  b->callback(toggle_cb, FL_WHEN_ENTER_KEY); y += 25;
134  b->tooltip("Do callback when user hits Enter key");
135  b = new Fl_Toggle_Button(10,y,200,25,"FL_WHEN_NOT_CHANGED");
136  b->callback(toggle_cb, FL_WHEN_NOT_CHANGED); y += 25;
137  b->tooltip("Do callback even if the text is not changed");
138  y += 5;
139  b = new Fl_Button(10,y,200,25,"&print changed()"); y += 25;
140  b->callback(button_cb);
141  b->tooltip("Print widgets that have changed() flag set");
142
143  b = new Fl_Light_Button(10,y,100,25," Tab Nav");
144  b->tooltip("Control tab navigation for the multiline input field");
145  b->callback(tabnav_cb, (void*)input[4]);
146  b->value(input[4]->tab_nav() ? 1 : 0);
147  b = new Fl_Light_Button(110,y,100,25," Arrow Nav"); y += 25;
148  b->tooltip("Control horizontal arrow key focus navigation behavior.\n"
149             "e.g. Fl::OPTION_ARROW_FOCUS");
150  b->callback(arrownav_cb);
151  b->value(input[4]->tab_nav() ? 1 : 0);
152  b->value(Fl::option(Fl::OPTION_ARROW_FOCUS) ? 1 : 0);
153
154  b = new Fl_Button(220,y1,120,25,"color"); y1 += 25;
155  b->color(input[0]->color()); b->callback(color_cb, (void*)0);
156  b->tooltip("Color behind the text");
157  b = new Fl_Button(220,y1,120,25,"selection_color"); y1 += 25;
158  b->color(input[0]->selection_color()); b->callback(color_cb, (void*)1);
159  b->labelcolor(fl_contrast(FL_BLACK,b->color()));
160  b->tooltip("Color behind selected text");
161  b = new Fl_Button(220,y1,120,25,"textcolor"); y1 += 25;
162  b->color(input[0]->textcolor()); b->callback(color_cb, (void*)2);
163  b->labelcolor(fl_contrast(FL_BLACK,b->color()));
164  b->tooltip("Color of the text");
165
166  window->end();
167  window->show(argc,argv);
168  return Fl::run();
169}
170
171//
172// End of "$Id: input.cxx 8419 2011-02-13 16:13:04Z greg.ercolano $".
173//
Note: See TracBrowser for help on using the repository browser.