/* * Implementation of FuncButton class. */ #include #include "FuncButton.h" /* * Declare a dummy button state to pass to the constructor of parent class * PushButton. */ ButtonState* DummyState = new ButtonState(1); /* * Constructor implementation. The parm F contains a pointer to a callback * function, which is stored in the member variable CallBack. Hence, the * CallBack member of each FuncButron instance contains a pointer to its * callback function. * * The constructor of the parent class PushButton wants three args: the button * label, a button state, and an initial state value. The values we pass up * for these args are the Label parm we get, a DummyState, and 0. We use a * dummy state value, since function buttons are intended to be stateless. If * one does want to change a state within a function button, then a pointer to * a state object should be passed as the value of the static parameter (see * below). The 0 value in the third arg makes the initial state of PushButton * such that it is drawn normally (a non-zero value makes the PushButton * display in reverse video). * * The third arg to the FuncButton constructor is a static parameter that is * sent to the call-back function. Typically this parm is a ptr to the parent * interactor in which the call-back resides, or a pointer to a state object * that the callback will change. */ FuncButton::FuncButton(FuncPtr Func, char *Label, void* StaticParm) : PushButton(Label, DummyState, 0) { CallBack = Func; CallBackParm = StaticParm; } /* * The virtual function Handle is exactly the same as Button::Handle, except * that here Press is sent the triggering event as an actual parm. */ void FuncButton::Handle (register Event& e) { if (e.eventType == DownEvent && e.target == this) { bool inside = true; do { if (enabled && e.target == this) { if (e.eventType == EnterEvent) { inside = true; } else if (e.eventType == LeaveEvent) { inside = false; } if (inside) { if (!hit) { hit = true; Refresh(); } } else { if (hit) { hit = false; Refresh(); } } } Read(e); } while (e.eventType != UpEvent); if (hit) { hit = false; Refresh(); } if (enabled && inside) { /* Press(e); -- error msg from g++ is VERY misleading */ Press(&e); } } } /* * The implementation of the virtual function Press simply calls the call back. * It passes the static call-back parm that was given to the constructor, and * the triggering event as the dynamic parm. */ void FuncButton::Press(Event* e) { CallBack(CallBackParm, e); }