00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef AMROC_EVENTHANDLER_H
00010 #define AMROC_EVENTHANDLER_H
00011
00019 #include <queue>
00020 #include <utility>
00021 #include <deque>
00022
00023 #include "IO/control-device.h"
00024
00025 #include <wsdepend.h>
00026 #include <X11/Xlib.h>
00027
00028 struct SetState {
00029 SetState(int o, long *iv, int ivlen, float *rv, int rvlen, char *st, int slen) :
00030 opt(o), str_len(slen) {
00031 ivec = new long[ivlen];
00032 for (int i=0; i<ivlen; i++)
00033 ivec[i] = iv[i];
00034
00035 rvec = new float[rvlen];
00036 for (int r=0; r<rvlen; r++)
00037 rvec[r] = rv[r];
00038
00039 str = new char[slen];
00040 for (int s=0; s<slen; s++)
00041 str[s] = st[s];
00042 }
00043
00044 ~SetState() {
00045 if (ivec)
00046 delete [] ivec;
00047 if (rvec)
00048 delete [] rvec;
00049 if (str)
00050 delete [] str;
00051 }
00052
00053 int opt;
00054 long *ivec;
00055 float *rvec;
00056 char *str;
00057 int str_len;
00058 };
00059
00060 struct SingleEvent {
00061 SingleEvent() :
00062 start(0), win(0), type(0), state(0), xe(1), ye(1), ststate((SetState *)0) {}
00063 SingleEvent(int st, int w, int t, int s) :
00064 start(st), win(w), type(t), state(s), xe(1), ye(1), ststate((SetState *)0) {}
00065 SingleEvent(int st, int w, int t, int s, int x, int y) :
00066 start(st), win(w), type(t), state(s), xe(x), ye(y), ststate((SetState *)0) {}
00067 SingleEvent(int st, int w, int t, int s, SetState *stst) :
00068 start(st), win(w), type(t), state(s), xe(1), ye(1), ststate(stst) {}
00069 SingleEvent(int st, int w, int t, int s, int x, int y, SetState *stst) :
00070 start(st), win(w), type(t), state(s), xe(x), ye(y), ststate(stst) {}
00071
00072 ~SingleEvent() {
00073
00074
00075 }
00076
00077 int start;
00078 int win;
00079 int type;
00080 int state;
00081 int xe, ye;
00082 SetState *ststate;
00083 };
00084
00085
00092 class VisualEventHandler {
00093 typedef std::queue<SingleEvent, std::deque<SingleEvent> > event_queue_type;
00094
00095 public:
00096 VisualEventHandler() : _NumberInits(0) {
00097 InitVariables();
00098 }
00099
00100 virtual ~VisualEventHandler() {}
00101
00102 virtual void SetUpQueue() {}
00103
00104 void ProcessEvent(int *iwin, int *type, int *xe, int *ye, int *state) {
00105 if (called == -1) {
00106 float dummy;
00107 char cstr[80];
00108 int opt = 0;
00109 V3_GETSTATE( &opt, winid, &dummy, cstr, 80);
00110 opt = -1;
00111 V3_GETSTATE( &opt, keybin, &dummy, cstr, 80);
00112 called = 0;
00113 _NumberInits++;
00114 SetUpQueue();
00115 return;
00116 }
00117 if (!_EventQueue.empty()) {
00118 if (called>=_EventQueue.front().start && *iwin==-1) {
00119 SingleEvent& Current = _EventQueue.front();
00120 if (Current.ststate) {
00121 SetState *CSSt = Current.ststate;
00122 V3_SETSTATE( &(CSSt->opt), CSSt->ivec, CSSt->rvec, CSSt->str, CSSt->str_len);
00123 delete Current.ststate;
00124 Current.ststate = (SetState *)0;
00125 Current.start++;
00126 *iwin = 0;
00127 *type = 0;
00128 *state = 0;
00129 *xe = 0;
00130 *ye = 0;
00131 return;
00132 }
00133
00134 *iwin = Current.win;
00135 *type = Current.type;
00136 *state = Current.state;
00137 *xe = Current.xe;
00138 *ye = Current.ye;
00139
00140 _EventQueue.pop();
00141 called = 0;
00142 }
00143 else
00144 called++;
00145 }
00146
00147 if (*state == keybin[19])
00148 InitVariables();
00149 }
00150
00151 inline event_queue_type& EventQueue() { return _EventQueue; }
00152 inline const event_queue_type& EventQueue() const { return _EventQueue; }
00153 inline void InitVariables() { called = -1; }
00154 inline const int& NumberInits() const { return _NumberInits; }
00155 inline int NumberInits() { return _NumberInits; }
00156 inline void SetNumberInits(int& ni) { _NumberInits = ni; }
00157
00158 protected:
00159 event_queue_type _EventQueue;
00160
00161 long winid[8];
00162 long keybin[32];
00163
00164 private:
00165 int called;
00166 int _NumberInits;
00167 };
00168
00169
00170 #endif