NEURON
ocpicker.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #if HAVE_IV // to end of file
3 
4 #include <OS/list.h>
5 #include <InterViews/hit.h>
6 #include <stdio.h>
7 #include "ocpicker.h"
8 #include "rubband.h"
9 
10 /*static*/ class ButtonHandler {
11 public:
12  ButtonHandler(EventButton, OcHandler*);
13  ButtonHandler(EventButton, Rubberband*);
14  ~ButtonHandler();
15  OcHandler* handler_;
16  Rubberband* rband_;
17  EventButton eb_;
18 };
19 
20 ButtonHandler::ButtonHandler(EventButton eb, OcHandler* a) {
21  eb_ = eb;
22  handler_ = a;
23  rband_ = NULL;
24  Resource::ref(a);
25 }
26 
27 ButtonHandler::ButtonHandler(EventButton eb, Rubberband* rb) {
28  eb_ = eb;
29  handler_ = NULL;
30  rband_ = rb;
31  Resource::ref(rb);
32 }
33 
34 ButtonHandler::~ButtonHandler() {
35  Resource::unref(handler_);
36  Resource::unref(rband_);
37 }
38 
39 declarePtrList(HandlerList, ButtonHandler);
40 implementPtrList(HandlerList, ButtonHandler);
41 
43 {
44  ms_ = unknown;
45  for (int i=0; i < unknown; ++i) {
46  handlers_[i] = new HandlerList(1);
47  }
48 }
50  for (int i=0; i < unknown; ++i) {
51  long cnt = handlers_[i]->count();
52  for (long j=0; j < cnt; j++) {
53  delete handlers_[i]->item(j);
54  }
55  delete handlers_[i];
56  }
57 }
58 bool StandardPicker::pick(Canvas* c, Glyph* glyph, int depth, Hit& h) {
59  if (!h.event()) {
60  return false;
61  }
62  const Event& e = *h.event();
63  if (e.grabber()) {
64  h.target(depth, glyph, 0, e.grabber());
65  return true;
66  }
67  event(e);
68 
69  long cnt = handlers_[ms_]->count();
70  for (long i=0; i < cnt; ++i) {
71  ButtonHandler& b = *handlers_[ms_]->item(i);
72  if (b.eb_ == Event::any || b.eb_ == mb_) {
73  if (b.handler_) {
74  h.target(depth, glyph, 0, b.handler_);
75  }else{
76  b.rband_->canvas(c);
77  h.target(depth, glyph, 0, b.rband_);
78  }
79  return true;
80  }
81  }
82  return false;
83 }
84 
85 /* from /interviews/input.cpp */
86 void StandardPicker::event(const Event& e) {
87  switch (e.type()) {
88  case Event::down:
89 //printf("press\n");
90  ms_ = press;
91  mb_ = e.pointer_button();
92  break;
93  case Event::motion:
94  if ((ms_ == drag || ms_ == press) &&
95  (e.left_is_down() || e.right_is_down() || e.middle_is_down())
96  ) {
97 //printf("drag\n");
98  ms_ = drag;
99  }else{
100 //printf("motion\n");
101  ms_ = motion;
102  mb_ = 0;
103  }
104  break;
105  case Event::up:
106 //printf("release\n");
107  ms_ = release;
108  mb_ = e.pointer_button();
109  break;
110  }
111 }
112 
113 void StandardPicker::unbind(int m, EventButton eb) {
114  long cnt = handlers_[m]->count();
115  long i, j;
116  for (i=0, j=0; i < cnt; ++i) {
117  ButtonHandler& b = *handlers_[m]->item(j);
118  if (b.eb_ == Event::any || b.eb_ == eb) {
119  delete handlers_[m]->item(j);
120  handlers_[m]->remove(j);
121  }else{
122  ++j;
123  }
124  }
125 }
126 
127 void StandardPicker::bind(int m, EventButton eb, OcHandler* h) {
128  unbind(m, eb);
129  if (h) {
130  handlers_[m]->append(new ButtonHandler(eb, h));
131  }
132 }
133 
135  int m = 1;
136  unbind(m, eb);
137  if (rb) {
138  handlers_[m]->append(new ButtonHandler(eb, rb));
139  }
140 }
141 
143  for (int m=0; m < unknown; ++m) {
144  unbind(m, eb);
145  }
146 }
147 #endif
#define declarePtrList(PtrList, T)
#define Glyph
Definition: _defines.h:132
void event(const Event &)
virtual ~StandardPicker()
void remove_all(EventButton)
virtual void ref() const
Definition: resource.cpp:47
#define e
Definition: passive0.cpp:24
#define implementPtrList(PtrList, T)
void bind_press(EventButton eb, Rubberband *)
virtual void drag(const Event &e)
Definition: ocinput.h:21
virtual void press(const Event &e)
Definition: ocinput.h:20
#define cnt
Definition: spt2queue.cpp:19
#define Canvas
Definition: _defines.h:65
void unbind(int, EventButton)
size_t j
virtual void unref() const
Definition: resource.cpp:52
#define Event
Definition: _defines.h:107
virtual void release(const Event &e)
Definition: ocinput.h:22
HandlerList * handlers_[4]
Definition: ocinput.h:32
#define i
Definition: md1redef.h:12
#define c
#define EventButton
Definition: _defines.h:21
void bind(int, EventButton eb, OcHandler *h)
virtual bool pick(Canvas *, Glyph *, int depth, Hit &h)
return NULL
Definition: cabcode.cpp:461
#define Hit
Definition: _defines.h:147