forms_free.cxx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // "$Id: forms_free.cxx 7903 2010-11-28 21:06:39Z matt $"
  3. //
  4. // Forms free widget routines 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. // Emulation of the Forms "free" widget.
  28. // This emulation allows the free demo to run, and has allowed
  29. // me to port several other programs, but it is in no way
  30. // complete.
  31. #include <FL/Fl.H>
  32. #include <FL/Fl_Free.H>
  33. void Fl_Free::step(void *v) {
  34. Fl_Free *f = (Fl_Free *)v;
  35. int old_event = Fl::e_number;
  36. f->handle(Fl::e_number == FL_STEP);
  37. Fl::e_number = old_event;
  38. Fl::add_timeout(.01,step,v);
  39. }
  40. /**
  41. Create a new Fl_Free widget with type, position, size, label and handler.
  42. \param[in] t type
  43. \param[in] X, Y, W, H position and size
  44. \param[in] L widget label
  45. \param[in] hdl handler function
  46. The constructor takes both the type and the handle function. The handle
  47. function should be declared as follows:
  48. \code
  49. int handle_function(Fl_Widget *w,
  50. int event,
  51. float event_x,
  52. float event_y,
  53. char key)
  54. \endcode
  55. This function is called from the handle() method in response to most
  56. events, and is called by the draw() method.
  57. The event argument contains the event type:
  58. \code
  59. // old event names for compatibility:
  60. #define FL_MOUSE FL_DRAG
  61. #define FL_DRAW 0
  62. #define FL_STEP 9
  63. #define FL_FREEMEM 12
  64. #define FL_FREEZE FL_UNMAP
  65. #define FL_THAW FL_MAP
  66. \endcode
  67. */
  68. Fl_Free::Fl_Free(uchar t,int X, int Y, int W, int H,const char *L,
  69. FL_HANDLEPTR hdl) :
  70. Fl_Widget(X,Y,W,H,L) {
  71. type(t);
  72. hfunc = hdl;
  73. if (t == FL_SLEEPING_FREE) set_flag(INACTIVE);
  74. if (t == FL_CONTINUOUS_FREE || t == FL_ALL_FREE)
  75. Fl::add_timeout(.01,step,this);
  76. }
  77. /**
  78. The destructor will call the handle function with the event FL_FREE_MEM.
  79. */
  80. Fl_Free::~Fl_Free() {
  81. Fl::remove_timeout(step,this);
  82. hfunc(this,FL_FREEMEM,0,0,0);
  83. }
  84. void Fl_Free::draw() {hfunc(this,FL_DRAW,0,0,0);}
  85. int Fl_Free::handle(int e) {
  86. char key = Fl::event_key();
  87. switch (e) {
  88. case FL_FOCUS:
  89. if (type()!=FL_INPUT_FREE && type()!=FL_ALL_FREE) return 0;
  90. break;
  91. case FL_PUSH:
  92. case FL_DRAG:
  93. case FL_RELEASE:
  94. key = 4-Fl::event_button();
  95. break;
  96. case FL_SHORTCUT:
  97. return 0;
  98. }
  99. if (hfunc(this, e, float(Fl::event_x()), float(Fl::event_y()), key)) do_callback();
  100. return 1;
  101. }
  102. //
  103. // End of "$Id: forms_free.cxx 7903 2010-11-28 21:06:39Z matt $".
  104. //