NEURON
scenepic.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 #if HAVE_IV // to end of file
3 
4 #include <IV-look/kit.h>
5 #include <InterViews/layout.h>
6 #include <InterViews/telltale.h>
7 #include <InterViews/window.h>
8 #include <OS/list.h>
9 #include <OS/string.h>
10 #include <stdio.h>
11 #include "ivoc.h"
12 #include "mymath.h"
13 #include "scenevie.h"
14 #include "scenepic.h"
15 #include "rubband.h"
16 #include "apwindow.h"
17 #include "utility.h"
18 #include "oc2iv.h"
19 
20 #define Scene_SceneMover_ "Translate Scene"
21 #define Scene_SceneZoom_ "ZoomInOut Scene"
22 #define Scene_RoundView_ "RoundView Scene"
23 #define Scene_WholeSceneView_ "WholeScene Scene"
24 #define Scene_WholePlotView_ "View_equal_Plot Scene"
25 #define Scene_ZoomOut10_ "ZoomOut10 Scene"
26 #define Scene_ZoomeIn10_ "ZoomIn10 Scene"
27 #define Scene_SpecView_ "SetView Scene"
28 #define Scene_SizeScene_ "Scene_equal_View Scene"
29 #define Scene_NewView_ "NewView Scene"
30 #define Scene_ShowMenu_ "Scene"
31 #define Scene_ObjectName_ "ObjectName"
32 
33 MenuItem* K::menu_item(const char* name) {
34  Glyph* g =
35  LayoutKit::instance()->r_margin(WidgetKit::instance()->fancy_label(name), 0.0, fil, 0.0);
36  return WidgetKit::instance()->menu_item(g);
37 }
38 
39 MenuItem* K::check_menu_item(const char* name) {
40  Glyph* g =
41  LayoutKit::instance()->r_margin(WidgetKit::instance()->fancy_label(name), 0.0, fil, 0.0);
42  return WidgetKit::instance()->check_menu_item(g);
43 }
44 
45 MenuItem* K::radio_menu_item(TelltaleGroup* tg, const char* name) {
46  Glyph* g =
47  LayoutKit::instance()->r_margin(WidgetKit::instance()->fancy_label(name), 0.0, fil, 0.0);
48  return WidgetKit::instance()->radio_menu_item(tg, g);
49 }
50 
51 /*static*/ class ButtonItemInfo {
52  public:
53  ButtonItemInfo(const char* name, Action*, TelltaleState*, MenuItem* mi = NULL, Menu* m = NULL);
54  virtual ~ButtonItemInfo();
55  GlyphIndex menu_index();
56  TelltaleState* s_;
57  CopyString name_;
58  Action* a_;
59  Menu* parent_;
60  MenuItem* mi_;
61 };
62 ButtonItemInfo::ButtonItemInfo(const char* name,
63  Action* a,
64  TelltaleState* s,
65  MenuItem* mi,
66  Menu* parent) {
67  name_ = name;
68  s_ = s;
69  a_ = a;
70  parent_ = parent;
71  mi_ = mi;
72 }
73 ButtonItemInfo::~ButtonItemInfo() {}
74 
75 GlyphIndex ButtonItemInfo::menu_index() {
76  GlyphIndex i, cnt;
77  if (parent_ && mi_) {
78  cnt = parent_->item_count();
79  for (i = 0; i < cnt; ++i) {
80  if (parent_->item(i) == mi_) {
81  return i;
82  }
83  }
84  }
85  return -1;
86 }
87 
88 declarePtrList(ButtonItemInfoList, ButtonItemInfo)
89 implementPtrList(ButtonItemInfoList, ButtonItemInfo)
90 
91 /*static*/ class SceneMover: public OcHandler {
92  public:
93  SceneMover();
94  virtual ~SceneMover();
95  virtual bool event(Event&);
96  virtual void help();
97 
98  private:
99  Coord x_, y_;
100  XYView* view_;
101 };
102 
103 /*static*/ class SceneZoom: public OcHandler {
104  public:
105  SceneZoom();
106  virtual ~SceneZoom();
107  virtual bool event(Event&);
108  virtual void help();
109 
110  private:
111  Coord x_, y_, xorg_, yorg_;
112  XYView* view_;
113 };
114 
115 /*static*/ class NewView: public RubberAction {
116  public:
117  NewView();
118  virtual ~NewView();
119  virtual void execute(Rubberband*);
120  virtual void help();
121 };
122 
123 /*static*/ class RoundView: public Action { virtual void execute(); };
124 
125 /*static*/ class WholeSceneView: public Action { virtual void execute(); };
126 
127 /*static*/ class WholePlotView: public Action { virtual void execute(); };
128 
129 /*static*/ class SpecView: public Action { virtual void execute(); };
130 
131 /*static*/ class SizeScene: public Action { virtual void execute(); };
132 
133 /*static*/ class ZoomOut10: public Action { virtual void execute(); };
134 
135 /*static*/ class ZoomIn10: public Action { virtual void execute(); };
136 
137 /*static*/ class SPObjectName: public Action { virtual void execute(); };
138 
139 /*static*/ class ShowMenu: public Action {
140  public:
141  ShowMenu(Menu*);
142  virtual ~ShowMenu();
143  virtual void execute();
144 
145  private:
146  Menu* m_;
147 };
148 
150  if (!picker_) {
151  WidgetKit& k = *WidgetKit::instance();
152  picker_ = new ScenePicker(this);
153 
154  SceneZoom* z = new SceneZoom();
155  SceneMover* m = new SceneMover();
156 
157  Menu* men = k.pulldown();
158  MenuItem* mi = K::menu_item("View . . .");
159  mi->menu(men);
160  picker_->add_menu(mi);
161 
162  picker_->add_menu("View = plot", new WholePlotView(), men);
163  picker_->add_menu("Set View", new SpecView(), men);
164  picker_->add_menu("10% Zoom out", new ZoomOut10(), men);
165  picker_->add_menu("10% Zoom in", new ZoomIn10(), men);
166  picker_->add_radio_menu("NewView", new RubberRect(new NewView()), 0, 0, men);
167  picker_->add_radio_menu("Zoom in/out", z, 0, men);
168  picker_->add_radio_menu("Translate", m, 0, men);
169  picker_->add_menu("Round View", new RoundView(), men);
170  picker_->add_menu("Whole Scene", new WholeSceneView(), men);
171  picker_->add_menu("Scene=View", new SizeScene(), men);
172  picker_->add_menu("Object Name", new SPObjectName(), men);
173  // picker_->add_menu("Show Menu", new ShowMenu(men), men);
174  // picker_->add_menu(k.menu_item("Undo"));
175  // picker_->add_menu(k.menu_item("Redo"));
176  picker_->add_menu(k.menu_item_separator());
177  picker_->bind_select(z);
178  picker_->bind_adjust(m);
179  }
180  return picker_;
181 }
182 
183 /*static*/ class ScenePickerImpl: public OcHandler {
184  public:
185  ScenePickerImpl(Scene*);
186  virtual ~ScenePickerImpl();
187  virtual bool event(Event&);
188  long info_index(const char*);
189 
190  public:
191  friend class ScenePicker;
192  PopupMenu* menu_;
193  Scene* scene_;
194  TelltaleGroup* tg_;
195  CopyString sel_name_;
196  ButtonItemInfoList* bil_;
197  static DismissableWindow* window_;
198 };
199 
200 void ScenePicker::pick_menu(Glyph* glyph, int depth, Hit& h) {
201  h.target(depth, glyph, 0, spi_);
202 }
203 
204 DismissableWindow* ScenePickerImpl::window_;
205 
206 /*static*/ class RadioSelect: public Action {
207  public:
208  RadioSelect(const char*, Action*, Scene*);
209  virtual ~RadioSelect();
210  virtual void execute();
211 
212  private:
213  Action* a_;
214  CopyString name_;
215  Scene* s_;
216 };
217 
218 /*static*/ class RubberTool: public Action {
219  public:
220  RubberTool(Action* sel, Rubberband*, ScenePicker*, int);
221  virtual ~RubberTool();
222  virtual void execute();
223 
224  private:
225  Action* sel_;
226  Rubberband* rb_;
227  ScenePicker* sp_;
228  int tool_;
229 };
230 
231 /*static*/ class HandlerTool: public Action {
232  public:
233  HandlerTool(OcHandler*, ScenePicker*, int);
234  virtual ~HandlerTool();
235  virtual void execute();
236 
237  private:
238  OcHandler* h_;
239  ScenePicker* sp_;
240  int tool_;
241 };
242 
244  spi_ = new ScenePickerImpl(scene);
245  spi_->ref();
246  bind_menu(spi_);
247 }
248 
250  return ScenePickerImpl::window_;
251 }
252 
254  spi_->unref();
255 }
256 
257 
259  return spi_->tg_;
260 }
261 
263  if (m) {
264  m->append_item(mi);
265  } else {
266  spi_->menu_->append_item(mi);
267  }
268  return mi;
269 }
270 
271 MenuItem* ScenePicker::add_menu(const char* name, MenuItem* mi, Menu* m) {
272  Menu* mm;
273  if (m) {
274  mm = m;
275  } else {
276  mm = spi_->menu_->menu();
277  }
278  mm->append_item(mi);
279  spi_->bil_->append(new ButtonItemInfo(name, mi->action(), mi->state(), mi, mm));
280  return mi;
281 }
282 
283 MenuItem* ScenePicker::add_menu(const char* name, Action* a, Menu* m) {
284  MenuItem* mi = K::menu_item(name);
285  mi->action(a);
286  return add_menu(name, mi, m);
287 }
288 MenuItem* ScenePicker::add_radio_menu(const char* name, Action* a, Menu* m) {
289  MenuItem* mi = K::radio_menu_item(spi_->tg_, name);
290  mi->action(new RadioSelect(name, a, spi_->scene_));
291  return add_menu(name, mi, m);
292 }
293 Button* ScenePicker::radio_button(const char* name, Action* a) {
294  Button* mi = WidgetKit::instance()->radio_button(spi_->tg_,
295  name,
296  new RadioSelect(name, a, spi_->scene_));
297  spi_->bil_->append(new ButtonItemInfo(name, mi->action(), mi->state()));
298  return mi;
299 }
301  Rubberband* rb,
302  Action* sel,
303  int tool,
304  Menu* m) {
305  return add_radio_menu(name, new RubberTool(sel, rb, this, tool), m);
306 }
307 Button* ScenePicker::radio_button(const char* name, Rubberband* rb, Action* sel, int tool) {
308  return radio_button(name, new RubberTool(sel, rb, this, tool));
309 }
310 MenuItem* ScenePicker::add_radio_menu(const char* name, OcHandler* h, int tool, Menu* m) {
311  return add_radio_menu(name, new HandlerTool(h, this, tool), m);
312 }
313 
314 long ScenePickerImpl::info_index(const char* name) {
315  long i, cnt;
316  cnt = bil_->count();
317  for (i = 0; i < cnt; ++i) {
318  ButtonItemInfo* b = bil_->item(i);
319  if (strcmp(b->name_.string(), name) == 0) {
320  return i;
321  }
322  }
323  return -1;
324 }
325 void ScenePicker::exec_item(const char* name) {
326  long i;
327  Scene* s = spi_->scene_;
328  if (s->view_count()) {
329  XYView* v = s->sceneview(0);
331  if (v->canvas()) {
332  ScenePickerImpl::window_ = (DismissableWindow*) v->canvas()->window();
333  }
334  } else {
336  ScenePickerImpl::window_ = NULL;
337  }
338  i = spi_->info_index(name);
339  if (i > -1) {
340  ButtonItemInfo* b = spi_->bil_->item(i);
341  TelltaleState* t = b->s_;
342  bool chosen = t->test(TelltaleState::is_chosen);
343  bool act = !chosen;
344  if (t->test(TelltaleState::is_toggle)) {
345  t->set(TelltaleState::is_chosen, act);
346  act = true;
347  } else if (t->test(TelltaleState::is_choosable)) {
348  t->set(TelltaleState::is_chosen, true);
349  }
350  t->notify();
351  if (act && b->a_ != NULL) {
352  b->a_->execute();
353  }
354  }
355 }
356 
357 void ScenePicker::remove_item(const char* name) {
358  long i;
359  i = spi_->info_index(name);
360  if (i > -1) {
361  ButtonItemInfo* b = spi_->bil_->item(i);
362  spi_->bil_->remove(i);
363  GlyphIndex j = b->menu_index();
364  if (j > -1) {
365  b->parent_->remove_item(j);
366  }
367  // if (b->mi_) {
368  // delete b->mi_;
369  // }
370  delete b;
371  }
372 }
373 
374 void ScenePicker::insert_item(const char* insert, const char* name, MenuItem* mi) {
375  long i;
376  i = spi_->info_index(insert);
377  if (i > -1) {
378  ButtonItemInfo* b = spi_->bil_->item(i);
379  GlyphIndex j = b->menu_index();
380  if (j > -1) {
381  b->parent_->insert_item(j, mi);
382  spi_->bil_->insert(i,
383  new ButtonItemInfo(name, mi->action(), mi->state(), mi, b->parent_));
384  }
385  }
386 }
387 
388 void ScenePicker::set_scene_tool(int t) {
389  spi_->scene_->tool(t);
390 }
391 
392 void ScenePicker::help() {
393  spi_->scene_->help();
394 }
395 
396 void ScenePicker::select_name(const char* name) {
397  spi_->sel_name_ = name;
398 }
399 
400 const char* ScenePicker::select_name() {
401  return spi_->sel_name_.string();
402 }
403 
404 ScenePickerImpl::ScenePickerImpl(Scene* scene)
405  : sel_name_("") {
406  menu_ = new PopupMenu();
407  menu_->ref();
408  tg_ = new TelltaleGroup();
409  tg_->ref();
410  scene_ = scene; // not ref'ed since picker deleted when scene is deleted
411  bil_ = new ButtonItemInfoList(20);
412 }
413 
414 ScenePickerImpl::~ScenePickerImpl() {
415  Resource::unref(menu_);
416  Resource::unref(tg_);
417  for (long i = bil_->count() - 1; i >= 0; --i) {
418  delete bil_->item(i);
419  }
420  delete bil_;
421 }
422 
423 bool ScenePickerImpl::event(Event& e) {
424  // printf("ScenePickerImpl::event\n");
425  window_ = (DismissableWindow*) e.window();
426  menu_->event(e);
427  return false;
428 }
429 
430 RubberTool::RubberTool(Action* sel, Rubberband* rb, ScenePicker* sp, int tool) {
431  sel_ = sel;
432  sp_ = sp;
433  rb_ = rb;
434  Resource::ref(rb_);
435  Resource::ref(sel_);
436  tool_ = tool;
437 }
438 
439 RubberTool::~RubberTool() {
440  Resource::unref(rb_);
441  Resource::unref(sel_);
442 }
443 
444 void RubberTool::execute() {
445  sp_->bind_select(rb_);
446  sp_->set_scene_tool(tool_);
447  if (Oc::helpmode()) {
448  rb_->help();
449  } else if (sel_) {
450  sel_->execute();
451  }
452 }
453 
454 RadioSelect::RadioSelect(const char* name, Action* a, Scene* s)
455  : name_(name) {
456  a_ = a;
457  Resource::ref(a_);
458  s_ = s; // not referenced
459 }
460 
461 RadioSelect::~RadioSelect() {
463 }
464 
465 void RadioSelect::execute() {
467  a_->execute();
468  s_->picker()->select_name(this->name_.string());
469  for (int i = 0; i < s_->view_count(); ++i) {
470  XYView* v = s_->sceneview(i);
471  v->notify();
472  }
473 }
474 
475 HandlerTool::HandlerTool(OcHandler* h, ScenePicker* sp, int tool) {
476  sp_ = sp;
477  h_ = h;
478  Resource::ref(h_);
479  tool_ = tool;
480 }
481 
482 HandlerTool::~HandlerTool() {
483  Resource::unref(h_);
484 }
485 
486 void HandlerTool::execute() {
487  sp_->bind_select(h_);
488  sp_->set_scene_tool(tool_);
489  if (Oc::helpmode()) {
490  if (h_) {
491  h_->help();
492  } else {
493  sp_->help();
494  }
495  }
496 }
497 
498 SceneMover::SceneMover() {
499  x_ = 0;
500  y_ = 0;
501 }
502 
503 SceneMover::~SceneMover() {}
504 
505 void SceneMover::help() {
506  Oc::help(Scene_SceneMover_);
507 }
508 
509 bool SceneMover::event(Event& e) {
510  if (Oc::helpmode()) {
511  if (e.type() == Event::down) {
512  help();
513  }
514  }
515  Coord xold = x_, yold = y_;
516  x_ = e.pointer_x();
517  y_ = e.pointer_y();
518 
519  switch (e.type()) {
520  case Event::down:
521  view_ = XYView::current_pick_view();
522  // view_->rebind();
523  e.grab(this);
524 #ifdef WIN32
525  e.window()->grab_pointer();
526 #endif
527  break;
528  case Event::motion:
529  view_->move_view(x_ - xold, y_ - yold);
530  break;
531  case Event::up:
532  e.ungrab(this);
533 #ifdef WIN32
534  e.window()->ungrab_pointer();
535 #endif
536  break;
537  }
538  return true;
539 }
540 
541 SceneZoom::SceneZoom() {
542  x_ = 0;
543  y_ = 0;
544  xorg_ = 0;
545  yorg_ = 0;
546 }
547 
548 SceneZoom::~SceneZoom() {}
549 
550 void SceneZoom::help() {
551  Oc::help(Scene_SceneZoom_);
552 }
553 
554 bool SceneZoom::event(Event& e) {
555  if (Oc::helpmode()) {
556  if (e.type() == Event::down) {
557  help();
558  }
559  }
560  Coord xold = x_, yold = y_;
561  x_ = e.pointer_x();
562  y_ = e.pointer_y();
563 
564  switch (e.type()) {
565  case Event::down:
566  view_ = XYView::current_pick_view();
567  // view_->rebind();
568  e.grab(this);
569 #ifdef WIN32
570  e.window()->grab_pointer();
571 #endif
572  xorg_ = x_;
573  yorg_ = y_;
574  break;
575  case Event::motion:
576  xold = (x_ - xold) / 50;
577  yold = (y_ - yold) / 50;
578  if (xold > .5)
579  xold = .5;
580  if (yold > .5)
581  yold = .5;
582  if (xold < -.5)
583  xold = -.5;
584  if (yold < -.5)
585  yold = -.5;
586  view_->scale_view(xorg_, yorg_, xold, yold);
587  break;
588  case Event::up:
589  e.ungrab(this);
590 #ifdef WIN32
591  e.window()->ungrab_pointer();
592 #endif
593  break;
594  }
595  return true;
596 }
597 
598 void RoundView::execute() {
599  if (Oc::helpmode()) {
600  Oc::help(Scene_RoundView_);
601  return;
602  }
604  if (!v)
605  return;
606  Coord x1, y1, x2, y2;
607  v->zin(x1, y1, x2, y2);
608  double d1, d2;
609  int ntic;
610  MyMath::round_range_down(x1, x2, d1, d2, ntic);
611  x1 = d1;
612  x2 = d2;
613  MyMath::round_range_down(y1, y2, d1, d2, ntic);
614  y1 = d1;
615  y2 = d2;
616 
617  v->size(x1, y1, x2, y2);
618  v->zout(x1, y1, x2, y2);
619  v->size(x1, y1, x2, y2);
620  v->damage_all();
621 }
622 
624  if (Oc::helpmode()) {
625  Oc::help(Scene_WholeSceneView_);
626  return;
627  }
629  if (!v)
630  return;
631  Scene& s = *v->scene();
632  v->size(s.x1(), s.y1(), s.x2(), s.y2());
633  Coord x1, y1, x2, y2;
634  v->zout(x1, y1, x2, y2);
635  v->size(x1, y1, x2, y2);
636  v->damage_all();
637 }
638 
639 void WholePlotView::execute() {
640  if (Oc::helpmode()) {
641  Oc::help(Scene_WholePlotView_);
642  return;
643  }
645  if (!v)
646  return;
647  Scene& s = *v->scene();
648  Coord x1, y1, x2, y2;
649  s.wholeplot(x1, y1, x2, y2);
650  MyMath::round(x1, x2, MyMath::Expand, 2);
651  MyMath::round(y1, y2, MyMath::Expand, 2);
652  v->box_size(x1, y1, x2, y2);
653  v->zout(x1, y1, x2, y2);
654  v->box_size(x1, y1, x2, y2);
655  v->damage_all();
656 }
657 
658 void ZoomOut10::execute() {
659  if (Oc::helpmode()) {
660  Oc::help(Scene_ZoomOut10_);
661  return;
662  }
664  Coord x1, x2, y1, y2;
665  v->zout(x1, y1, x2, y2);
666  v->size(x1, y1, x2, y2);
667  v->damage_all();
668 }
669 
670 void ZoomIn10::execute() {
671  if (Oc::helpmode()) {
672  Oc::help(Scene_ZoomeIn10_);
673  return;
674  }
676  if (!v)
677  return;
678  Coord x1, x2, y1, y2;
679  v->zin(x1, y1, x2, y2);
680  v->size(x1, y1, x2, y2);
681  v->damage_all();
682 }
683 
684 void SPObjectName::execute() {
685  if (Oc::helpmode()) {
686  Oc::help(Scene_ObjectName_);
687  }
689  printf("%s\n", hoc_object_name(s->hoc_obj_ptr()));
690 }
691 
692 void SpecView::execute() {
693  if (Oc::helpmode()) {
694  Oc::help(Scene_SpecView_);
695  }
697  if (!v)
698  return;
699  Coord x1, x2, y1, y2;
700  v->zin(x1, y1, x2, y2);
701  bool bx = var_pair_chooser("X size", x1, x2, v->canvas()->window());
702  bool by = var_pair_chooser("Y size", y1, y2, v->canvas()->window());
703  v->size(x1, y1, x2, y2);
704  v->zout(x1, y1, x2, y2);
705  v->size(x1, y1, x2, y2);
706  v->damage_all();
707 }
708 
709 void SizeScene::execute() {
710  if (Oc::helpmode()) {
711  Oc::help(Scene_SizeScene_);
712  return;
713  }
715  if (!v)
716  return;
717  Coord x1, x2, y1, y2;
718  v->zin(x1, y1, x2, y2);
719  v->scene()->new_size(x1, y1, x2, y2);
720  v->zout(x1, y1, x2, y2);
721  v->size(x1, y1, x2, y2);
722 }
723 
724 NewView::NewView() {}
725 NewView::~NewView() {}
726 void NewView::help() {
727  Oc::help(Scene_NewView_);
728 }
729 
730 void NewView::execute(Rubberband* rb) {
731  if (Oc::helpmode()) {
732  help();
733  return;
734  }
735  const Event& e = rb->event();
737  Coord l, b, r, t;
738  Coord x1, y1, x2, y2;
739  ((RubberRect*) rb)->get_rect_canvas(l, b, r, t);
740  ((RubberRect*) rb)->get_rect(x1, y1, x2, y2);
741  XYView* v = cv->new_view(x1, y1, x2, y2);
742  ViewWindow* w = new ViewWindow(v, ((PrintableWindow*) (cv->canvas()->window()))->type());
743  w->place(l + e.pointer_root_x() - e.pointer_x(), b + e.pointer_root_y() - e.pointer_y());
744  w->map();
745 }
746 
747 ShowMenu::ShowMenu(Menu* m) {
748  m_ = m;
749  m->ref();
750 }
751 ShowMenu::~ShowMenu() {
752  Resource::unref(m_);
753 }
754 void ShowMenu::execute() {
755  if (Oc::helpmode()) {
756  Oc::help(Scene_ShowMenu_);
757  return;
758  }
760  v->parent()->viewmenu(m_);
761 }
762 
763 // following doesn't work correctly yet
764 void OcViewGlyph::viewmenu(Glyph* m) {
765  printf("OcViewGlyph::viewmenu()\n");
766  if (!g_) {
767  g_ = body();
768  Resource::ref(g_);
769  LayoutKit& lk = *LayoutKit::instance();
770  WidgetKit& wk = *WidgetKit::instance();
771  PolyGlyph* hbox = lk.hbox(2);
772  hbox->append(lk.center(m, 0, 1));
773  hbox->append(lk.center(view(), 0, 1));
774  body(hbox);
775  printf("add menu\n");
776  } else {
777  printf("delete menu\n");
778  body(g_);
780  g_ = NULL;
781  }
782 }
783 
785  menu_ = WidgetKit::instance()->pulldown();
786  menu_->ref();
787  w_ = NULL;
788  grabbed_ = false;
789 }
790 
793  if (w_) {
794  delete w_;
795  }
796 }
797 
798 bool PopupMenu::event(Event& e) {
799  if (!w_) {
800  w_ = new PopupWindow(menu_);
801 #if MAC
802  w_->place(10000, 10000);
803  w_->map();
804  w_->unmap();
805 #endif
806  }
807  switch (e.type()) {
808  case Event::down:
809  if (!grabbed_) {
810  Coord l, b;
811  w_->place(e.pointer_root_x(), e.pointer_root_y());
812  w_->align(.8, .9);
813 #if defined(WIN32) || MAC
814  l = w_->left();
815  b = w_->bottom();
816  if (b < 0. || l < 0.) {
817  w_->align(0., 0.);
818  w_->place((l > 0.) ? l : 1., (b > 0.) ? b : 20.);
819  }
820  w_->map();
821 #else
822  w_->map();
823  l = w_->left();
824  b = w_->bottom();
825  if (b < 0. || l < 0.) {
826  w_->unmap();
827  w_->align(0., 0.);
828  w_->place((l > 0.) ? l : 1., (b > 0.) ? b : 20.);
829  w_->map();
830  }
831 #endif
832  e.grab(this);
833  grabbed_ = true;
834  menu_->press(e);
835  }
836  break;
837  case Event::motion:
838  if (grabbed_) {
839  menu_->drag(e);
840  }
841  break;
842  case Event::up:
843  if (grabbed_) {
844  e.ungrab(this);
845  grabbed_ = false;
846  w_->unmap();
847  menu_->release(e);
848  }
849  break;
850  }
851  return true;
852 }
853 
855  menu_->append_item(mi);
856 }
857 #endif
#define TelltaleState
Definition: _defines.h:296
#define Menu
Definition: _defines.h:176
#define PopupWindow
Definition: _defines.h:210
#define PopupMenu
Definition: _defines.h:209
#define Coord
Definition: _defines.h:19
#define Hit
Definition: _defines.h:147
#define WidgetKit
Definition: _defines.h:331
#define GlyphIndex
Definition: _defines.h:23
#define MenuItem
Definition: _defines.h:179
#define Event
Definition: _defines.h:107
#define Button
Definition: _defines.h:62
#define PolyGlyph
Definition: _defines.h:207
#define TelltaleGroup
Definition: _defines.h:295
#define RubberRect
Definition: _defines.h:240
#define LayoutKit
Definition: _defines.h:161
#define Action
Definition: _defines.h:27
#define Glyph
Definition: _defines.h:132
static MenuItem * radio_menu_item(TelltaleGroup *, const char *)
static MenuItem * menu_item(const char *)
static MenuItem * check_menu_item(const char *)
static void round_range_down(Coord x1, Coord x2, double &y1, double &y2, int &ntic)
Definition: mymath.cpp:301
@ Expand
Definition: mymath.h:52
static double round(float &x1, float &x2, int direction, int digits)
Definition: mymath.cpp:330
virtual void help()
static void help(const char *)
static bool helpmode()
Definition: ivoc.h:70
XYView * view()
Definition: scenevie.h:95
Glyph * g_
Definition: scenevie.h:103
void viewmenu(Glyph *)
bool grabbed_
Definition: utility.h:78
virtual bool event(Event &)
void append_item(MenuItem *)
virtual ~PopupMenu()
Menu * menu_
Definition: utility.h:76
PopupWindow * w_
Definition: utility.h:77
virtual void map()
virtual void ref() const
Definition: resource.cpp:47
virtual void unref() const
Definition: resource.cpp:52
virtual void execute(Rubberband *)
virtual void help()
virtual bool event(Event &)
Object * hoc_obj_ptr()
Definition: scenevie.h:306
virtual XYView * sceneview(int) const
virtual Coord y2() const
Definition: scenevie.h:366
virtual Coord y1() const
Definition: scenevie.h:363
ScenePicker * picker()
virtual int view_count() const
virtual void wholeplot(Coord &x1, Coord &y1, Coord &x2, Coord &y2) const
ScenePicker * picker_
Definition: scenevie.h:337
virtual Coord x2() const
Definition: scenevie.h:360
virtual Coord x1() const
Definition: scenevie.h:357
virtual void pick_menu(Glyph *, int, Hit &)
virtual ~ScenePicker()
virtual const char * select_name()
void insert_item(const char *, const char *, MenuItem *)
MenuItem * add_radio_menu(const char *, Action *, Menu *=NULL)
Button * radio_button(const char *, Action *)
MenuItem * add_menu(MenuItem *, Menu *=NULL)
virtual void help()
TelltaleGroup * telltale_group()
ScenePickerImpl * spi_
Definition: scenepic.h:54
void remove_item(const char *)
virtual void exec_item(const char *)
virtual void set_scene_tool(int)
static DismissableWindow * last_window()
ScenePicker(Scene *)
void bind_menu(Rubberband *rb)
Definition: ocpicker.h:29
void bind_select(Rubberband *rb)
Definition: ocpicker.h:23
void bind_adjust(Rubberband *rb)
Definition: ocpicker.h:26
Canvas * canvas()
virtual Scene * scene() const
virtual XYView * new_view(Coord x1, Coord y1, Coord x2, Coord y2)
static XYView * current_pick_view()
void execute(Inst *p)
Definition: code.cpp:2661
double mm
Definition: coord.h:49
#define fil
Definition: coord.h:42
double t
Definition: cvodeobj.cpp:59
char * hoc_object_name(Object *ob)
Definition: hoc_oop.cpp:72
static void help(const char *)
Definition: hel2mos.cpp:107
#define implementPtrList(PtrList, T)
#define declarePtrList(PtrList, T)
#define v
Definition: md1redef.h:4
#define i
Definition: md1redef.h:12
char * name
Definition: init.cpp:16
#define printf
Definition: mwprefix.h:26
size_t j
static philox4x32_key_t k
Definition: nrnran123.cpp:11
static N_Vector y_
static realtype a_
static N_Vector x_
void handle_old_focus()
#define g
Definition: passive0.cpp:21
#define e
Definition: passive0.cpp:22
#define parent
Definition: rbtqueue.cpp:47
#define cnt
Definition: spt2queue.cpp:19
#define NULL
Definition: sptree.h:16
static double insert(void *v)
Definition: tqueue.cpp:22
bool var_pair_chooser(const char *, float &x, float &y, Window *w=NULL, Coord x1=400., Coord y1=400.)