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