fltk  1.3.5-source
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X.
  Fossies Dox: fltk-1.3.5-source.tar.bz2  ("inofficial" and yet experimental doxygen-generated source code documentation)  

forms_compatability.cxx
Go to the documentation of this file.
1 //
2 // "$Id$"
3 //
4 // Forms compatibility functions for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
19 // Forms library compatibility functions.
20 // Many more functions are defined as inlines in forms.h!
21 
22 #include <FL/forms.H>
23 #include <stdlib.h>
24 
25 char fl_flip = 2;
26 void fl_end_form() {
28 }
30  // set the dimensions of a group to surround contents
31  if (children() && !w()) {
32  Fl_Widget*const* a = array();
33  Fl_Widget* o = *a++;
34  int rx = o->x();
35  int ry = o->y();
36  int rw = rx+o->w();
37  int rh = ry+o->h();
38  for (int i=children_-1; i--;) {
39  o = *a++;
40  if (o->x() < rx) rx = o->x();
41  if (o->y() < ry) ry = o->y();
42  if (o->x()+o->w() > rw) rw = o->x()+o->w();
43  if (o->y()+o->h() > rh) rh = o->y()+o->h();
44  }
45  x(rx);
46  y(ry);
47  w(rw-rx);
48  h(rh-ry);
49  }
50  // flip all the children's coordinate systems:
51  if (fl_flip) {
52  Fl_Widget* o = (type()>=FL_WINDOW) ? this : window();
53  int Y = o->h();
54  Fl_Widget*const* a = array();
55  for (int i=children(); i--;) {
56  Fl_Widget* ow = *a++;
57  int newy = Y-ow->y()-ow->h();
58  ow->y(newy);
59  }
60  }
61  end();
62 }
63 
64 static int initargc;
65 static char **initargv;
66 
67 void fl_initialize(int *argc, char **argv, const char *, FL_CMD_OPT *, int) {
68  initargc = *argc;
69  initargv = new char*[*argc+1];
70  int i,j;
71  for (i=0; i<=*argc; i++) initargv[i] = argv[i];
72  for (i=j=1; i<*argc; ) {
73  if (Fl::arg(*argc,argv,i));
74  else argv[j++] = argv[i++];
75  }
76  argv[j] = 0;
77  *argc = j;
78  if (fl_flip==2) fl_flip = 0;
79 }
80 
81 char fl_modal_next; // set by fl_freeze_forms()
82 
83 void fl_show_form(Fl_Window *f,int place,int b,const char *n) {
84 
85  f->label(n);
86  if (!b) f->clear_border();
87  if (fl_modal_next || b==FL_TRANSIENT) {f->set_modal(); fl_modal_next = 0;}
88 
89  if (place & FL_PLACE_MOUSE) f->hotspot(f);
90 
91  if (place & FL_PLACE_CENTER) {
92  int scr_x, scr_y, scr_w, scr_h;
93  Fl::screen_xywh(scr_x, scr_y, scr_w, scr_h);
94  f->position(scr_x+(scr_w-f->w())/2, scr_y+(scr_h-f->h())/2);
95  }
96 
97  if (place & FL_PLACE_FULLSCREEN)
98  f->fullscreen();
99 
100  if (place & (FL_PLACE_POSITION | FL_PLACE_GEOMETRY))
101  f->position(
102  (f->x() < 0) ? Fl::w()-f->w()+f->x()-1 : f->x(),
103  (f->y() < 0) ? Fl::h()-f->h()+f->y()-1 : f->y());
104 
105 // if (place & FL_PLACE_ASPECT) {
106 // this is not yet implemented
107 // it can be done by setting size_range().
108 
109  if (place == FL_PLACE_FREE || place == FL_PLACE_SIZE)
110  f->free_position();
111 
112  if (place == FL_PLACE_FREE || place & FL_FREE_SIZE)
113  if (!f->resizable()) f->resizable(f);
114 
115  if (initargc) {f->show(initargc,initargv); initargc = 0;}
116  else f->show();
117 }
118 
120  Fl_Widget *obj;
121  while (!(obj = Fl::readqueue())) if (!Fl::wait()) exit(0);
122  return obj;
123 }
124 
126  Fl::check();
127  return Fl::readqueue();
128 }
129 
130 void fl_set_graphics_mode(int /*r*/,int /*d*/) {}
131 
132 #ifndef FL_DOXYGEN // FIXME: suppress doxygen warning
134  draw_box();
135  align(align()|FL_ALIGN_INSIDE); // questionable method of compatibility
136  draw_label();
137 }
138 #endif
139 
140 // Create a forms button by selecting correct fltk subclass:
141 
142 #include <FL/Fl_Return_Button.H>
143 #include <FL/Fl_Repeat_Button.H>
144 
145 Fl_Button *fl_add_button(uchar t,int x,int y,int w,int h,const char *l) {
146  Fl_Button *b;
147  switch (t) {
148  case FL_RETURN_BUTTON:
150  b = new Fl_Return_Button(x,y,w,h,l);
151  break;
152  case FL_TOUCH_BUTTON:
153  b = new Fl_Repeat_Button(x,y,w,h,l);
154  break;
155  default:
156  b = new Fl_Button(x,y,w,h,l);
157  }
158  switch (t) {
159  case FL_TOGGLE_BUTTON:
160  case FL_RADIO_BUTTON:
161  b->type(t);
162  break;
163  case FL_HIDDEN_BUTTON:
165  b->type(FL_HIDDEN_BUTTON);
166  break;
167  case FL_INOUT_BUTTON:
168  b->when(FL_WHEN_CHANGED);
169  break;
170  }
171  return b;
172 }
173 
174 void fl_show_message(const char *q1,const char *q2,const char *q3) {
175  fl_message("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"");
176 }
177 
178 void fl_show_alert(const char *q1,const char *q2,const char *q3,int) {
179  fl_alert("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"");
180 }
181 
182 int fl_show_question(const char *q1,const char *q2,const char *q3) {
183  return fl_choice("%s\n%s\n%s", "No", "Yes", 0L, q1?q1:"", q2?q2:"", q3?q3:"");
184 }
185 
187  const char *q1,
188  const char *q2,
189  const char *q3,
190  int, // number of buttons, ignored
191  const char *b0,
192  const char *b1,
193  const char *b2) {
194  return fl_choice("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"", b0,b1,b2)+1;
195 }
196 
197 char *fl_show_simple_input(const char *str1, const char *defstr) {
198  const char *r = fl_input("%s", defstr, str1);
199  return (char *)(r ? r : defstr);
200 }
201 
202 //
203 // End of "$Id$".
204 //
Fl_Widget::draw_label
void draw_label() const
Definition: fl_labeltype.cxx:99
fl_do_forms
Fl_Widget * fl_do_forms(void)
Definition: forms_compatability.cxx:119
Fl_FormsText::draw
void draw()
Definition: forms_compatability.cxx:133
fl_check_forms
Fl_Widget * fl_check_forms()
Definition: forms_compatability.cxx:125
fl_show_choice
int fl_show_choice(const char *q1, const char *q2, const char *q3, int, const char *b0, const char *b1, const char *b2)
Definition: forms_compatability.cxx:186
FL_PLACE_POSITION
Definition: forms.H:283
Fl_Widget::y
int y() const
Definition: Fl_Widget.H:289
FL_PLACE_FREE
Definition: forms.H:280
FL_RETURN_BUTTON
#define FL_RETURN_BUTTON
Definition: forms.H:471
Fl_Widget::align
Fl_Align align() const
Definition: Fl_Widget.H:348
Fl_Widget::draw_box
void draw_box() const
Definition: fl_boxtype.cxx:442
Fl_Return_Button.H
fl_flip
char fl_flip
Definition: forms_compatability.cxx:25
FL_TOGGLE_BUTTON
#define FL_TOGGLE_BUTTON
value() toggles between 0 and 1 at every click of the button
Definition: Fl_Button.H:33
Fl_Group::end
void end()
Definition: Fl_Group.cxx:75
fl_message
void fl_message(const char *,...)
Definition: fl_ask.cxx:338
Fl_Group::children_
int children_
Definition: Fl_Group.H:46
fl_show_message
void fl_show_message(const char *q1, const char *q2, const char *q3)
Definition: forms_compatability.cxx:174
Fl_Button
Buttons generate callbacks when they are clicked by the user.
Definition: Fl_Button.H:79
Fl_Widget::window
Fl_Window * window() const
Definition: Fl_Window.cxx:118
Fl::readqueue
static Fl_Widget * readqueue()
Definition: Fl_Widget.cxx:76
FL_PLACE_CENTER
Definition: forms.H:282
forms.H
Fl::screen_xywh
static void screen_xywh(int &X, int &Y, int &W, int &H)
Definition: Fl.H:1000
FL_FREE_SIZE
Definition: forms.H:290
FL_CMD_OPT
#define FL_CMD_OPT
Definition: forms.H:158
Fl_Widget::x
int x() const
Definition: Fl_Widget.H:284
Fl::arg
static int arg(int argc, char **argv, int &i)
Definition: Fl_arg.cxx:130
FL_WINDOW
#define FL_WINDOW
window type id all subclasses have type() >= this
Definition: Fl_Window.H:33
b
long b
Definition: jpegint.h:397
FL_PLACE_MOUSE
Definition: forms.H:281
fl_choice
int fl_choice(const char *q, const char *b0, const char *b1, const char *b2,...)
Definition: fl_ask.cxx:459
Fl::h
static int h()
Definition: Fl_win32.cxx:571
FL_PLACE_FULLSCREEN
Definition: forms.H:287
Fl_Widget::w
int w() const
Definition: Fl_Widget.H:294
FL_INOUT_BUTTON
#define FL_INOUT_BUTTON
Definition: forms.H:470
FL_ALIGN_INSIDE
const Fl_Align FL_ALIGN_INSIDE
Definition: Enumerations.H:843
Fl_Repeat_Button.H
Fl::check
static int check()
Definition: Fl.cxx:688
FL_WHEN_CHANGED
Do the callback only when the widget value changes.
Definition: Enumerations.H:441
Fl_Widget::w
void w(int v)
Definition: Fl_Widget.H:143
Fl_Widget::x
void x(int v)
Definition: Fl_Widget.H:139
fl_input
const char * fl_input(const char *label, const char *deflt=0,...)
Definition: fl_ask.cxx:505
fl_end_form
void fl_end_form()
Definition: forms_compatability.cxx:26
FL_PLACE_GEOMETRY
Definition: forms.H:285
Fl_Group::array
Fl_Widget *const * array() const
Definition: Fl_Group.cxx:44
fl_set_graphics_mode
void fl_set_graphics_mode(int, int)
Definition: forms_compatability.cxx:130
Fl_Window
Definition: Fl_Window.H:57
Fl_Return_Button
Definition: Fl_Return_Button.H:33
fl_show_simple_input
char * fl_show_simple_input(const char *str1, const char *defstr)
Definition: forms_compatability.cxx:197
fl_initialize
void fl_initialize(int *argc, char **argv, const char *, FL_CMD_OPT *, int)
Definition: forms_compatability.cxx:67
Fl_Widget
Definition: Fl_Widget.H:101
Fl_Group::current
static Fl_Group * current()
Definition: Fl_Group.cxx:84
Fl_Widget::h
int h() const
Definition: Fl_Widget.H:299
Fl_Group::children
int children() const
Definition: Fl_Group.H:75
Fl_Widget::h
void h(int v)
Definition: Fl_Widget.H:145
fl_show_question
int fl_show_question(const char *q1, const char *q2, const char *q3)
Definition: forms_compatability.cxx:182
Fl_Widget::y
void y(int v)
Definition: Fl_Widget.H:141
fl_show_form
void fl_show_form(Fl_Window *f, int place, int b, const char *n)
Definition: forms_compatability.cxx:83
initargv
static char ** initargv
Definition: forms_compatability.cxx:65
x
int x
Definition: test.c:73
Fl::wait
static int wait()
Definition: Fl.cxx:666
fl_show_alert
void fl_show_alert(const char *q1, const char *q2, const char *q3, int)
Definition: forms_compatability.cxx:178
y
int y
Definition: test.c:74
Fl_Widget::type
uchar type() const
Definition: Fl_Widget.H:274
f
Fl_Box_Draw_F * f
Definition: fl_boxtype.cxx:285
Y
static int Y
Definition: Fl_Tooltip.cxx:76
FL_RADIO_BUTTON
#define FL_RADIO_BUTTON
Definition: Fl_Button.H:34
Fl::w
static int w()
Definition: Fl_win32.cxx:579
fl_modal_next
char fl_modal_next
Definition: forms_compatability.cxx:81
FL_PLACE_SIZE
Definition: forms.H:284
initargc
static int initargc
Definition: forms_compatability.cxx:64
FL_TRANSIENT
Definition: forms.H:298
uchar
unsigned char uchar
Definition: fl_types.h:30
Fl_Group::forms_end
void forms_end()
Definition: forms_compatability.cxx:29
fl_alert
void fl_alert(const char *,...)
Definition: fl_ask.cxx:361
FL_TOUCH_BUTTON
#define FL_TOUCH_BUTTON
Definition: forms.H:469
FL_HIDDEN_BUTTON
#define FL_HIDDEN_BUTTON
for Forms compatibility
Definition: Fl_Button.H:39
Fl_Repeat_Button
Definition: Fl_Repeat_Button.H:33
fl_add_button
Fl_Button * fl_add_button(uchar t, int x, int y, int w, int h, const char *l)
Definition: forms_compatability.cxx:145
FL_HIDDEN_RET_BUTTON
#define FL_HIDDEN_RET_BUTTON
Definition: forms.H:472