You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
5.6KB

  1. //
  2. // "$Id: forms_compatability.cxx 7903 2010-11-28 21:06:39Z matt $"
  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; 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. // Forms library compatibility functions.
  28. // Many more functions are defined as inlines in forms.h!
  29. #include <FL/forms.H>
  30. #include <stdlib.h>
  31. char fl_flip = 2;
  32. void fl_end_form() {
  33. while (Fl_Group::current()) Fl_Group::current()->forms_end();
  34. }
  35. void Fl_Group::forms_end() {
  36. // set the dimensions of a group to surround contents
  37. if (children() && !w()) {
  38. Fl_Widget*const* a = array();
  39. Fl_Widget* o = *a++;
  40. int rx = o->x();
  41. int ry = o->y();
  42. int rw = rx+o->w();
  43. int rh = ry+o->h();
  44. for (int i=children_-1; i--;) {
  45. o = *a++;
  46. if (o->x() < rx) rx = o->x();
  47. if (o->y() < ry) ry = o->y();
  48. if (o->x()+o->w() > rw) rw = o->x()+o->w();
  49. if (o->y()+o->h() > rh) rh = o->y()+o->h();
  50. }
  51. x(rx);
  52. y(ry);
  53. w(rw-rx);
  54. h(rh-ry);
  55. }
  56. // flip all the children's coordinate systems:
  57. if (fl_flip) {
  58. Fl_Widget* o = (type()>=FL_WINDOW) ? this : window();
  59. int Y = o->h();
  60. Fl_Widget*const* a = array();
  61. for (int i=children(); i--;) {
  62. Fl_Widget* ow = *a++;
  63. int newy = Y-ow->y()-ow->h();
  64. ow->y(newy);
  65. }
  66. }
  67. end();
  68. }
  69. static int initargc;
  70. static char **initargv;
  71. void fl_initialize(int *argc, char **argv, const char *, FL_CMD_OPT *, int) {
  72. initargc = *argc;
  73. initargv = new char*[*argc+1];
  74. int i,j;
  75. for (i=0; i<=*argc; i++) initargv[i] = argv[i];
  76. for (i=j=1; i<*argc; ) {
  77. if (Fl::arg(*argc,argv,i));
  78. else argv[j++] = argv[i++];
  79. }
  80. argv[j] = 0;
  81. *argc = j;
  82. if (fl_flip==2) fl_flip = 0;
  83. }
  84. char fl_modal_next; // set by fl_freeze_forms()
  85. void fl_show_form(Fl_Window *f,int place,int b,const char *n) {
  86. f->label(n);
  87. if (!b) f->clear_border();
  88. if (fl_modal_next || b==FL_TRANSIENT) {f->set_modal(); fl_modal_next = 0;}
  89. if (place & FL_PLACE_MOUSE) f->hotspot(f);
  90. if (place & FL_PLACE_CENTER) {
  91. int scr_x, scr_y, scr_w, scr_h;
  92. Fl::screen_xywh(scr_x, scr_y, scr_w, scr_h);
  93. f->position(scr_x+(scr_w-f->w())/2, scr_y+(scr_h-f->h())/2);
  94. }
  95. if (place & FL_PLACE_FULLSCREEN)
  96. f->fullscreen();
  97. if (place & (FL_PLACE_POSITION | FL_PLACE_GEOMETRY))
  98. f->position(
  99. (f->x() < 0) ? Fl::w()-f->w()+f->x()-1 : f->x(),
  100. (f->y() < 0) ? Fl::h()-f->h()+f->y()-1 : f->y());
  101. // if (place & FL_PLACE_ASPECT) {
  102. // this is not yet implemented
  103. // it can be done by setting size_range().
  104. if (place == FL_PLACE_FREE || place == FL_PLACE_SIZE)
  105. f->free_position();
  106. if (place == FL_PLACE_FREE || place & FL_FREE_SIZE)
  107. if (!f->resizable()) f->resizable(f);
  108. if (initargc) {f->show(initargc,initargv); initargc = 0;}
  109. else f->show();
  110. }
  111. Fl_Widget *fl_do_forms(void) {
  112. Fl_Widget *obj;
  113. while (!(obj = Fl::readqueue())) if (!Fl::wait()) exit(0);
  114. return obj;
  115. }
  116. Fl_Widget *fl_check_forms() {
  117. Fl::check();
  118. return Fl::readqueue();
  119. }
  120. void fl_set_graphics_mode(int /*r*/,int /*d*/) {}
  121. #ifndef FL_DOXYGEN // FIXME: suppress doxygen warning
  122. void Fl_FormsText::draw() {
  123. draw_box();
  124. align(align()|FL_ALIGN_INSIDE); // questionable method of compatibility
  125. draw_label();
  126. }
  127. #endif
  128. // Create a forms button by selecting correct fltk subclass:
  129. #include <FL/Fl_Return_Button.H>
  130. #include <FL/Fl_Repeat_Button.H>
  131. Fl_Button *fl_add_button(uchar t,int x,int y,int w,int h,const char *l) {
  132. Fl_Button *b;
  133. switch (t) {
  134. case FL_RETURN_BUTTON:
  135. case FL_HIDDEN_RET_BUTTON:
  136. b = new Fl_Return_Button(x,y,w,h,l);
  137. break;
  138. case FL_TOUCH_BUTTON:
  139. b = new Fl_Repeat_Button(x,y,w,h,l);
  140. break;
  141. default:
  142. b = new Fl_Button(x,y,w,h,l);
  143. }
  144. switch (t) {
  145. case FL_TOGGLE_BUTTON:
  146. case FL_RADIO_BUTTON:
  147. b->type(t);
  148. break;
  149. case FL_HIDDEN_BUTTON:
  150. case FL_HIDDEN_RET_BUTTON:
  151. b->type(FL_HIDDEN_BUTTON);
  152. break;
  153. case FL_INOUT_BUTTON:
  154. b->when(FL_WHEN_CHANGED);
  155. break;
  156. }
  157. return b;
  158. }
  159. void fl_show_message(const char *q1,const char *q2,const char *q3) {
  160. fl_message("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"");
  161. }
  162. void fl_show_alert(const char *q1,const char *q2,const char *q3,int) {
  163. fl_alert("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"");
  164. }
  165. int fl_show_question(const char *q1,const char *q2,const char *q3) {
  166. return fl_choice("%s\n%s\n%s", "No", "Yes", 0L, q1?q1:"", q2?q2:"", q3?q3:"");
  167. }
  168. int fl_show_choice(
  169. const char *q1,
  170. const char *q2,
  171. const char *q3,
  172. int, // number of buttons, ignored
  173. const char *b0,
  174. const char *b1,
  175. const char *b2) {
  176. return fl_choice("%s\n%s\n%s", q1?q1:"", q2?q2:"", q3?q3:"", b0,b1,b2)+1;
  177. }
  178. char *fl_show_simple_input(const char *str1, const char *defstr) {
  179. const char *r = fl_input("%s", defstr, str1);
  180. return (char *)(r ? r : defstr);
  181. }
  182. //
  183. // End of "$Id: forms_compatability.cxx 7903 2010-11-28 21:06:39Z matt $".
  184. //