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

forms_compatability.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: forms_compatability.cxx 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // Forms compatibility functions for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00028 // Forms library compatibility functions.
00029 // Many more functions are defined as inlines in forms.h!
00030 
00031 #include <FL/forms.H>
00032 #include <stdlib.h>
00033 
00034 char fl_flip = 2;
00035 void fl_end_form() {
00036   while (Fl_Group::current()) Fl_Group::current()->forms_end();
00037 }
00038 void Fl_Group::forms_end() {
00039   // set the dimensions of a group to surround contents
00040   if (children() && !w()) {
00041     Fl_Widget*const* a = array();
00042     Fl_Widget* o = *a++;
00043     int rx = o->x();
00044     int ry = o->y();
00045     int rw = rx+o->w();
00046     int rh = ry+o->h();
00047     for (int i=children_-1; i--;) {
00048       o = *a++;
00049       if (o->x() < rx) rx = o->x();
00050       if (o->y() < ry) ry = o->y();
00051       if (o->x()+o->w() > rw) rw = o->x()+o->w();
00052       if (o->y()+o->h() > rh) rh = o->y()+o->h();
00053     }
00054     x(rx);
00055     y(ry);
00056     w(rw-rx);
00057     h(rh-ry);
00058   }
00059   // flip all the children's coordinate systems:
00060   if (fl_flip) {
00061     Fl_Widget* o = (type()>=FL_WINDOW) ? this : window();
00062     int Y = o->h();
00063     Fl_Widget*const* a = array();
00064     for (int i=children(); i--;) {
00065       Fl_Widget* ow = *a++;
00066       int newy = Y-ow->y()-ow->h();
00067       ow->y(newy);
00068     }
00069   }
00070   end();
00071 }
00072 
00073 static int initargc;
00074 static char **initargv;
00075 
00076 void fl_initialize(int *argc, char **argv, const char *, FL_CMD_OPT *, int) {
00077   initargc = *argc;
00078   initargv = new char*[*argc+1];
00079   int i,j;
00080   for (i=0; i<=*argc; i++) initargv[i] = argv[i];
00081   for (i=j=1; i<*argc; ) {
00082     if (Fl::arg(*argc,argv,i));
00083     else argv[j++] = argv[i++];
00084   }
00085   argv[j] = 0;
00086   *argc = j;
00087   if (fl_flip==2) fl_flip = 0;
00088 }
00089 
00090 char fl_modal_next; // set by fl_freeze_forms()
00091 
00092 void fl_show_form(Fl_Window *f,int place,int b,const char *n) {
00093 
00094   f->label(n);
00095   if (!b) f->clear_border();
00096   if (fl_modal_next || b==FL_TRANSIENT) {f->set_modal(); fl_modal_next = 0;}
00097 
00098   if (place & FL_PLACE_MOUSE) f->hotspot(f);
00099 
00100   if (place & FL_PLACE_CENTER) {
00101     int scr_x, scr_y, scr_w, scr_h;
00102     Fl::screen_xywh(scr_x, scr_y, scr_w, scr_h);
00103     f->position(scr_x+(scr_w-f->w())/2, scr_y+(scr_h-f->h())/2);
00104   }
00105 
00106   if (place & FL_PLACE_FULLSCREEN)
00107     f->fullscreen();
00108 
00109   if (place & (FL_PLACE_POSITION | FL_PLACE_GEOMETRY))
00110     f->position(
00111       (f->x() < 0) ? Fl::w()-f->w()+f->x()-1 : f->x(),
00112       (f->y() < 0) ? Fl::h()-f->h()+f->y()-1 : f->y());
00113 
00114 // if (place & FL_PLACE_ASPECT) {
00115 // this is not yet implemented
00116 // it can be done by setting size_range().
00117 
00118   if (place == FL_PLACE_FREE || place == FL_PLACE_SIZE)
00119     f->free_position();
00120 
00121   if (place == FL_PLACE_FREE || place & FL_FREE_SIZE)
00122     if (!f->resizable()) f->resizable(f);
00123 
00124   if (initargc) {f->show(initargc,initargv); initargc = 0;}
00125   else f->show();
00126 }
00127 
00128 Fl_Widget *fl_do_forms(void) {
00129   Fl_Widget *obj;
00130   while (!(obj = Fl::readqueue())) if (!Fl::wait()) exit(0);
00131   return obj;
00132 }
00133 
00134 Fl_Widget *fl_check_forms() {
00135   Fl::check();
00136   return Fl::readqueue();
00137 }
00138 
00139 void fl_set_graphics_mode(int /*r*/,int /*d*/) {}
00140 
00141 #ifndef FL_DOXYGEN // FIXME: suppress doxygen warning
00142 void Fl_FormsText::draw() {
00143   draw_box();
00144   align(align()|FL_ALIGN_INSIDE); // questionable method of compatibility
00145   draw_label();
00146 }
00147 #endif
00148 
00149 // Create a forms button by selecting correct fltk subclass:
00150 
00151 #include <FL/Fl_Return_Button.H>
00152 #include <FL/Fl_Repeat_Button.H>
00153 
00154 Fl_Button *fl_add_button(uchar t,int x,int y,int w,int h,const char *l) {
00155   Fl_Button *b;
00156   switch (t) {
00157   case FL_RETURN_BUTTON:
00158   case FL_HIDDEN_RET_BUTTON:
00159     b = new Fl_Return_Button(x,y,w,h,l);
00160     break;
00161   case FL_TOUCH_BUTTON:
00162     b = new Fl_Repeat_Button(x,y,w,h,l);
00163     break;
00164   default:
00165     b = new Fl_Button(x,y,w,h,l);
00166   }
00167   switch (t) {
00168   case FL_TOGGLE_BUTTON:
00169   case FL_RADIO_BUTTON:
00170     b->type(t);
00171     break;
00172   case FL_HIDDEN_BUTTON:
00173   case FL_HIDDEN_RET_BUTTON:
00174     b->type(FL_HIDDEN_BUTTON);
00175     break;
00176   case FL_INOUT_BUTTON:
00177     b->when(FL_WHEN_CHANGED);
00178     break;
00179   }
00180   return b;
00181 }
00182 
00183 void fl_show_message(const char *q1,const char *q2,const char *q3) {
00184   fl_message("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"");
00185 }
00186 
00187 void fl_show_alert(const char *q1,const char *q2,const char *q3,int) {
00188   fl_alert("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"");
00189 }
00190 
00191 int fl_show_question(const char *q1,const char *q2,const char *q3) {
00192   return fl_choice("%s\n%s\n%s", "No", "Yes", 0L, q1?q1:"", q2?q2:"", q3?q3:"");
00193 }
00194 
00195 int fl_show_choice(
00196   const char *q1,
00197   const char *q2,
00198   const char *q3,
00199   int, // number of buttons, ignored
00200   const char *b0,
00201   const char *b1,
00202   const char *b2) {
00203   return fl_choice("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"", b0,b1,b2)+1;
00204 }
00205 
00206 char *fl_show_simple_input(const char *str1, const char *defstr) {
00207   const char *r = fl_input("%s", defstr, str1);
00208   return (char *)(r ? r : defstr);
00209 }
00210 
00211 //
00212 // End of "$Id: forms_compatability.cxx 7903 2010-11-28 21:06:39Z matt $".
00213 //