NEURON
ocbox.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 #if HAVE_IV
4 #include <OS/string.h>
5 #include <InterViews/polyglyph.h>
6 #include <InterViews/layout.h>
7 #include <InterViews/place.h>
8 #include <InterViews/patch.h>
9 #include <InterViews/background.h>
10 #include <InterViews/box.h>
11 #include <IV-look/kit.h>
12 #include <InterViews/input.h>
13 #include <ivstream.h>
14 #include <stdio.h>
15 #include "ocbox.h"
16 #include "apwindow.h"
17 #include "objcmd.h"
18 #include "ivoc.h"
19 #endif /* HAVE_IV */
20 
21 #include <InterViews/resource.h>
22 #include "oc2iv.h"
23 #include "classreg.h"
24 
25 #include "gui-redirect.h"
26 
27 extern int hoc_return_type_code;
28 
29 extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj);
30 extern double (*nrnpy_object_to_double_)(Object*);
31 
32 #if HAVE_IV
33 
34 class NrnFixedLayout: public Layout {
35  public:
36  NrnFixedLayout(const DimensionName, Coord span);
37  virtual ~NrnFixedLayout();
38 
39  virtual void request(GlyphIndex count, const Requisition*, Requisition& result);
40  virtual void allocate(const Allocation& given,
41  GlyphIndex count,
42  const Requisition*,
44  virtual void span(Coord);
45  virtual Coord span() {
46  return span_;
47  }
48  virtual bool vertical() {
49  return dimension_ == Dimension_Y;
50  }
51 
52  private:
53  DimensionName dimension_;
54  Coord span_;
55 };
56 
57 /*static*/ class OcBoxImpl {
58  public:
59  PolyGlyph* ocglyph_list_;
60  PolyGlyph* box_;
61  Object* oc_ref_; // reference to oc "this"
62  CopyString* save_action_;
63  Object* save_pyact_;
64  int type_;
65  ostream* o_;
66  Object* keep_ref_;
67  CopyString* dis_act_;
68  Object* dis_pyact_;
69  bool dismissing_;
70  Coord next_map_adjust_;
72  bool full_request_;
73 };
74 
75 /*static*/ class BoxAdjust: public InputHandler {
76  public:
77  BoxAdjust(OcBox*, OcBoxImpl*, Glyph*, Coord natural);
78  virtual ~BoxAdjust();
79  virtual void press(const Event&);
80  virtual void drag(const Event&);
81  virtual void release(const Event&);
82  NrnFixedLayout* fixlay_;
83  OcBox* b_;
84  OcBoxImpl* bi_;
85  Glyph* ga_; // not part of this glyph.
86  Coord pstart_, fstart_;
87 };
88 
89 /*static*/ class BoxDismiss: public WinDismiss {
90  public:
91  BoxDismiss(DismissableWindow*, String*, OcBox*, Object* pyact = NULL);
92  virtual ~BoxDismiss();
93  virtual void execute();
94 
95  private:
96  HocCommand* hc_;
97  OcBox* b_;
98 };
99 
100 BoxDismiss::BoxDismiss(DismissableWindow* w, String* s, OcBox* b, Object* pyact)
101  : WinDismiss(w) {
102  if (pyact) {
103  hc_ = new HocCommand(pyact);
104  } else {
105  hc_ = new HocCommand(s->string());
106  }
107  b_ = b;
108 }
109 BoxDismiss::~BoxDismiss() {
110  delete hc_;
111 }
112 void BoxDismiss::execute() {
113  if (b_->dismissing() == true) {
115  } else {
116  hc_->execute();
117  }
118 }
119 #endif /* HAVE_IV */
120 static void* vcons(Object*) {
121  TRY_GUI_REDIRECT_OBJ("VBox", NULL);
122 #if HAVE_IV
123  OcBox* b = NULL;
124  int frame = OcBox::INSET;
125  bool scroll = false;
126  if (ifarg(1))
127  frame = int(chkarg(1, 0, 3));
128  if (ifarg(2) && int(chkarg(2, 0, 1)) == 1) {
129  scroll = true;
130  }
131  b = new OcBox(OcBox::V, frame, scroll);
132  b->ref();
133  return (void*) b;
134 #else
135  return nullptr;
136 #endif /* HAVE_IV */
137 }
138 
139 static void* hcons(Object*) {
140  TRY_GUI_REDIRECT_OBJ("HBox", NULL);
141 #if HAVE_IV
142  OcBox* b = NULL;
143  int frame = OcBox::INSET;
144  if (ifarg(1))
145  frame = int(chkarg(1, 0, 3));
146  b = new OcBox(OcBox::H, frame);
147  b->ref();
148  return (void*) b;
149 #else
150  return nullptr;
151 #endif /* HAVE_IV */
152 }
153 
154 static void destruct(void* v) {
155  // TODO: this doesn't seem to get called; why?
156  TRY_GUI_REDIRECT_NO_RETURN("~Box", v);
157 #if HAVE_IV
158  OcBox* b = (OcBox*) v;
159  IFGUI
160  if (b->has_window()) {
161  b->window()->dismiss();
162  }
163  ENDGUI
164  b->unref();
165 #endif /* HAVE_IV */
166 }
167 
168 static double intercept(void* v) {
169  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.intercept", v);
170 #if HAVE_IV
171  bool b = int(chkarg(1, 0., 1.));
172  IFGUI((OcBox*) v)->intercept(b);
173  ENDGUI
174  return double(b);
175 #else
176  return 0.;
177 #endif /* HAVE_IV */
178 }
179 
180 static double ses_pri(void* v) {
181  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.priority", v);
182 #if HAVE_IV
183  int p = int(chkarg(1, -1000, 10000));
184  IFGUI((OcBox*) v)->session_priority(p);
185  ENDGUI
186  return double(p);
187 #else
188  return 0.;
189 #endif /* HAVE_IV */
190 }
191 
192 static double map(void* v) {
193  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.map", v);
194 #if HAVE_IV
195  IFGUI
196  OcBox* b = (OcBox*) v;
197  PrintableWindow* w;
198  b->premap();
199  if (ifarg(3)) {
200  w = b->make_window(float(*getarg(2)),
201  float(*getarg(3)),
202  float(*getarg(4)),
203  float(*getarg(5)));
204  } else {
205  w = b->make_window();
206  }
207  if (ifarg(1)) {
208  char* name = gargstr(1);
209  w->name(name);
210  }
211  b->dismissing(false);
212  w->map();
213  if (b->full_request() && b->has_window()) {
214  b->window()->request_on_resize(true);
215  }
216  b->dismiss_action(NULL);
217  ENDGUI
218  return 1.;
219 #else
220  return 0.;
221 #endif /* HAVE_IV */
222 }
223 
224 static double dialog(void* v) {
225  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.dialog", v);
226 #if HAVE_IV
227  bool r = false;
228  IFGUI
229  OcBox* b = (OcBox*) v;
230  const char* a = "Accept";
231  const char* c = "Cancel";
232  if (ifarg(2)) {
233  a = gargstr(2);
234  }
235  if (ifarg(3)) {
236  c = gargstr(3);
237  }
238  Oc oc;
239  oc.notify();
240  r = b->dialog(gargstr(1), a, c);
241  ENDGUI
242  return double(r);
243 #else
244  return 0.;
245 #endif /* HAVE_IV */
246 }
247 
248 static double unmap(void* v) {
249  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.unmap", v);
250 #if HAVE_IV
251  IFGUI
252  OcBox* b = (OcBox*) v;
253  bool accept = true;
254  if (ifarg(1)) {
255  accept = (bool) chkarg(1, 0, 1);
256  }
257  if (b->dialog_dismiss(accept)) {
258  return 0.;
259  }
260  if (b->has_window()) {
261  b->ref();
262  b->dismissing(true);
263  b->window()->dismiss();
264  b->window(NULL); // so we don't come back here again before
265  // printable window destructor called
266  b->unref();
267  }
268  ENDGUI
269  return 0.;
270 #else
271  return 0.;
272 #endif /* HAVE_IV */
273 }
274 
275 static double ismapped(void* v) {
277  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.ismapped", v);
278 #if HAVE_IV
279  bool b = false;
280  IFGUI
281  b = ((OcBox*) v)->has_window();
282  ENDGUI
283  return double(b);
284 #else
285  return 0.;
286 #endif /* HAVE_IV */
287 }
288 
289 static double adjuster(void* v) {
290  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.adjuster", v);
291 #if HAVE_IV
292  IFGUI((OcBox*) v)->adjuster(chkarg(1, -1., 1e5));
293  ENDGUI
294 #endif /* HAVE_IV */
295  return 0.;
296 }
297 
298 static double adjust(void* v) {
299  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.adjust", v);
300 #if HAVE_IV
301  IFGUI
302  int index = 0;
303  if (ifarg(2)) {
304  index = (int) chkarg(2, 0, 1000);
305  }
306  ((OcBox*) v)->adjust(chkarg(1, -1., 1e5), index);
307  ENDGUI
308 #endif /* HAVE_IV */
309  return 0.;
310 }
311 
312 static double full_request(void* v) {
313  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.full_request", v);
314 #if HAVE_IV
315  IFGUI
316  OcBox* b = (OcBox*) v;
317  if (ifarg(1)) {
318  bool x = ((int) chkarg(1, 0, 1) != 0) ? true : false;
319  b->full_request(x);
320  }
321  return (b->full_request() ? 1. : 0.);
322  ENDGUI
323 #endif /* HAVE_IV */
324  return 0.;
325 }
326 
327 static double b_size(void* v) {
328  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.size", v);
329 #if HAVE_IV
330  IFGUI
331  double* p = hoc_pgetarg(1); // array for at least 4 numbers
332  OcBox* b = (OcBox*) v;
333  if (b->has_window()) {
334  p[0] = b->window()->save_left();
335  p[1] = b->window()->save_bottom();
336  p[2] = b->window()->width();
337  p[3] = b->window()->height();
338  }
339  ENDGUI
340 #endif
341  return 0.;
342 }
343 
344 const char* pwm_session_filename();
345 
346 static double save(void* v) {
347  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.save", v);
348 #if HAVE_IV
349  IFGUI
350  OcBox* b = (OcBox*) v;
351  char buf[256];
352  if (hoc_is_object_arg(1)) {
353  b->save_action(0, *hoc_objgetarg(1));
354  return 1.;
355  } else if (ifarg(2)) {
356  if (hoc_is_double_arg(2)) { // return save session file name
358  return 1.;
359  } else {
360  sprintf(buf, "execute(\"%s\", %s)", gargstr(1), gargstr(2));
361  }
362  } else {
363  // sprintf(buf, "%s", gargstr(1));
364  b->save_action(gargstr(1), 0);
365  return 1.0;
366  }
367  b->save_action(buf, 0);
368  ENDGUI
369  return 1.;
370 #else
371  return 0.;
372 #endif /* HAVE_IV */
373 }
374 
375 /* help ref
376 .ref(objectvar)
377  solves the problem of keeping an anonymous hoc object which should
378  be destroyed when the window it manages is dismissed.
379  The box keeps a pointer to the hoc object and the object is
380  referenced when the box has a window and unreferenced when the window
381  is dismissed.
382 */
383 static double ref(void* v) {
384  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.ref", v);
385 #if HAVE_IV
386  OcBox* b = (OcBox*) v;
387  b->keep_ref(*hoc_objgetarg(1));
388  return 0.;
389 #else
390  Object* ob = *hoc_objgetarg(1);
391  hoc_obj_ref(ob);
392  return 0.;
393 #endif /* HAVE_IV */
394 }
395 
396 /* help dismiss_action
397 .dismiss_action("action")
398  execute the action when the vbox is dismissed from the screen.
399 */
400 static double dismiss_action(void* v) {
401  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("Box.dismiss_action", v);
402 #if HAVE_IV
403  IFGUI
404  OcBox* b = (OcBox*) v;
405  if (hoc_is_object_arg(1)) {
406  b->dismiss_action(0, *hoc_objgetarg(1));
407  } else {
408  b->dismiss_action(gargstr(1));
409  }
410  ENDGUI
411  return 0.;
412 #else
413  return 0.;
414 #endif /* HAVE_IV */
415 }
416 
417 static Member_func members[] = {"intercept",
418  intercept, // #if HAVE_IV ok
419  "adjuster",
420  adjuster, // #if HAVE_IV ok
421  "adjust",
422  adjust, // #if HAVE_IV ok
423  "full_request",
424  full_request, // #if HAVE_IV ok
425  "save",
426  save, // #if HAVE_IV ok
427  "map",
428  map, // #if HAVE_IV ok
429  "unmap",
430  unmap, // #if HAVE_IV ok
431  "ismapped",
432  ismapped, // #if HAVE_IV ok
433  "ref",
434  ref, // #if HAVE_IV ok
435  "dismiss_action",
436  dismiss_action, // #if HAVE_IV ok
437  "dialog",
438  dialog, // #if HAVE_IV ok
439  "priority",
440  ses_pri,
441  "size",
442  b_size,
443  0,
444  0};
445 
446 void HBox_reg() {
447  class2oc("HBox", hcons, destruct, members, NULL, NULL, NULL);
448 }
449 
450 void VBox_reg() {
451  class2oc("VBox", vcons, destruct, members, NULL, NULL, NULL);
452 }
453 #if HAVE_IV
455  : OcGlyph(NULL) {
456  parent_ = NULL;
457  recurse_ = false;
458 }
459 
460 void OcGlyphContainer::request(Requisition& r) const {
461  if (!recurse_) {
463  t->recurse_ = true;
464  OcGlyph::request(r);
465  Coord w, h;
466  w = h = -1.;
467  def_size(w, h);
468  if (w != -1.) {
469  r.x_requirement().natural(w);
470  r.y_requirement().natural(h);
471  }
472  t->recurse_ = false;
473  } else {
474  hoc_execerror("Box or Deck is recursive. The GUI may no longer work correctly.\n",
475  "Exit program and eliminate the recursion");
476  }
477 }
478 OcBox::OcBox(int type, int frame, bool scroll)
479  : OcGlyphContainer() {
480  ScrollBox* sb;
481  PolyGlyph* box;
482  bi_ = new OcBoxImpl;
483  bi_->full_request_ = false;
484  bi_->dismissing_ = false;
485  bi_->next_map_adjust_ = -1.;
486  bi_->ocglyph_list_ = new PolyGlyph();
487  bi_->ba_list_ = NULL;
488  Resource::ref(bi_->ocglyph_list_);
489  bi_->box_ = NULL;
490  IFGUI
491  WidgetKit& wk = *WidgetKit::instance();
492  LayoutKit& lk = *LayoutKit::instance();
493  if (type == H) {
494  box = bi_->box_ = lk.hbox(3);
495  } else {
496  if (scroll) {
497  bi_->box_ = sb = lk.vscrollbox(10);
498  box = lk.hbox(sb, lk.hspace(4), wk.vscroll_bar(sb));
499  } else {
500  box = bi_->box_ = lk.vbox(3);
501  //((Box*)box)->debug_ = new char[50];
502  // sprintf(((Box*)box)->debug_, "box%p:", this);
503  // printf("%s\n", ((Box*)box)->debug_);
504  }
505  }
506  Resource::ref(bi_->box_);
507 
508  switch (frame) {
509  case INSET:
510  body(new Background(wk.inset_frame(lk.variable_span(box)), wk.background()));
511  break;
512  case OUTSET:
513  body(new Background(wk.outset_frame(lk.variable_span(box)), wk.background()));
514  break;
515  case BRIGHT_INSET:
516  body(new Background(wk.bright_inset_frame(lk.variable_span(box)), wk.background()));
517  break;
518  case FLAT:
519  body(new Background(lk.variable_span(box), wk.background()));
520  break;
521  }
522  ENDGUI
523  bi_->type_ = type;
524  bi_->oc_ref_ = NULL;
525  bi_->save_action_ = NULL;
526  bi_->save_pyact_ = NULL;
527  bi_->o_ = NULL;
528  bi_->keep_ref_ = NULL;
529  bi_->dis_act_ = NULL;
530  bi_->dis_pyact_ = NULL;
531 }
532 
533 OcBox::~OcBox() {
534  // printf("~OcBox\n");
535  GlyphIndex i, cnt = bi_->ocglyph_list_->count();
536  for (i = 0; i < cnt; ++i) {
537  ((OcGlyph*) (bi_->ocglyph_list_->component(i)))->parents(false);
538  }
539  Resource::unref(bi_->ocglyph_list_);
540  Resource::unref(bi_->box_);
541  Resource::unref(bi_->ba_list_);
542  hoc_obj_unref(bi_->oc_ref_);
543  if (bi_->save_action_) {
544  delete bi_->save_action_;
545  }
546  if (bi_->save_pyact_) {
547  hoc_obj_unref(bi_->save_pyact_);
548  }
549  if (bi_->dis_act_) {
550  delete bi_->dis_act_;
551  }
552  if (bi_->dis_pyact_) {
553  hoc_obj_unref(bi_->dis_pyact_);
554  }
555  assert(!bi_->keep_ref_);
556  delete bi_;
557 }
558 
559 bool OcBox::full_request() {
560  return bi_->full_request_;
561 }
562 void OcBox::full_request(bool b) {
563  bi_->full_request_ = b;
564 }
565 bool OcBox::dismissing() {
566  return bi_->dismissing_;
567 }
568 void OcBox::dismissing(bool d) {
569  bi_->dismissing_ = d;
570 }
571 
572 void OcGlyphContainer::intercept(bool b) {
573  if (b) {
575  } else {
577  parent_ = NULL;
578  }
579 }
580 
581 void OcBox::box_append(OcGlyph* g) {
582  WidgetKit& wk = *WidgetKit::instance();
583  LayoutKit& lk = *LayoutKit::instance();
584  bi_->ocglyph_list_->append(g);
585  g->parents(true);
586  if (bi_->next_map_adjust_ > 0.) {
587  BoxAdjust* ba = new BoxAdjust(this, bi_, g, bi_->next_map_adjust_);
588  if (!bi_->ba_list_) {
589  bi_->ba_list_ = new PolyGlyph(1);
590  bi_->ba_list_->ref();
591  }
592  bi_->ba_list_->append(ba);
593  bi_->box_->append(ba->ga_);
594  bi_->box_->append(ba);
595  bi_->next_map_adjust_ = -1.;
596  } else {
597  if (bi_->type_ == V) {
598  bi_->box_->append(lk.hflexible(lk.vcenter(g, 1.)));
599  } else {
600  bi_->box_->append(lk.vflexible(lk.vcenter(g, 1.)));
601  }
602  }
603 }
604 
605 void OcBox::premap() {
606  if (bi_->ba_list_) {
607  body(new Patch(body()));
608  }
609 }
610 
611 void OcBox::adjuster(Coord natural) {
612  bi_->next_map_adjust_ = natural;
613 }
614 
615 void OcBox::adjust(Coord natural, int index) {
616  // printf("OcBox::adjust %g %d\n", natural, index);
617  if (bi_->ba_list_ && index < bi_->ba_list_->count()) {
618  BoxAdjust* ba = (BoxAdjust*) bi_->ba_list_->component(index);
619  adjust(natural, ba);
620  }
621 }
622 void OcBox::adjust(Coord natural, BoxAdjust* ba) {
623  ba->fixlay_->span(natural);
624  Box::full_request(true);
625  bi_->box_->modified(0);
626  // ((Patch*)body())->reallocate();
627  ((Patch*) body())->redraw();
628  Box::full_request(false);
629 }
630 
631 NrnFixedLayout::NrnFixedLayout(const DimensionName d, Coord span) {
632  dimension_ = d;
633  span_ = span;
634 }
635 
636 NrnFixedLayout::~NrnFixedLayout() {}
637 
638 void NrnFixedLayout::request(GlyphIndex, const Requisition*, Requisition& result) {
639  Requirement& r = result.requirement(dimension_);
640  r.natural(span_);
641  r.stretch(0.0);
642  r.shrink(0.0);
643 }
644 
645 void NrnFixedLayout::allocate(const Allocation&,
646  GlyphIndex,
647  const Requisition*,
648  Allocation* result) {
649  Allotment& a = result[0].allotment(dimension_);
650  a.span(span_);
651 }
652 
653 void NrnFixedLayout::span(Coord s) {
654  span_ = s;
655 }
656 
657 BoxAdjust::BoxAdjust(OcBox* b, OcBoxImpl* bi, Glyph* g, Coord natural)
658  : InputHandler(NULL, WidgetKit::instance()->style()) {
659  b_ = b;
660  bi_ = bi;
661  LayoutKit& lk = *LayoutKit::instance();
662  fixlay_ = new NrnFixedLayout(bi->type_ == OcBox::V ? Dimension_Y : Dimension_X, natural);
663  ga_ = lk.vcenter(g, 1.);
664  if (bi->type_ == OcBox::V) {
665  ga_ = lk.hflexible(ga_);
666  body(lk.vspace(10));
667  } else {
668  ga_ = lk.vflexible(ga_);
669  body(lk.hspace(10));
670  }
671  ga_ = new Placement(ga_, fixlay_);
672 }
673 
674 BoxAdjust::~BoxAdjust() {}
675 
676 void BoxAdjust::press(const Event& e) {
677  if (fixlay_->vertical()) {
678  pstart_ = e.pointer_y();
679  } else {
680  pstart_ = e.pointer_x();
681  }
682  fstart_ = fixlay_->span();
683 }
684 
685 void BoxAdjust::drag(const Event& e) {
686  Coord d;
687  if (fixlay_->vertical()) {
688  d = e.pointer_y() - pstart_;
689  d = fstart_ - d;
690  } else {
691  d = e.pointer_x() - pstart_;
692  d = fstart_ + d;
693  }
694  if (d < 10.) {
695  d = 10.;
696  }
697  b_->adjust(d, this);
698 }
699 
700 void BoxAdjust::release(const Event& e) {
701  drag(e);
702 }
703 
704 void OcBox::save_action(const char* creat, Object* pyact) {
705  if (bi_->o_) {
706  // old endl cause great slowness on remote filesystem
707  // with gcc version 3.3 20030226 (prerelease) (SuSE Linux)
708  //*bi_->o_ << creat << endl;
709  *bi_->o_ << creat << "\n";
710  } else {
711  if (pyact) {
712  bi_->save_pyact_ = pyact;
713  hoc_obj_ref(pyact);
714  } else {
715  bi_->save_action_ = new CopyString(creat);
716  }
717  }
718 }
719 
720 void OcBox::dismiss_action(const char* act, Object* pyact) {
721  if (pyact) {
722  hoc_obj_ref(pyact);
723  bi_->dis_pyact_ = pyact;
724  if (bi_->dis_act_) {
725  delete bi_->dis_act_;
726  bi_->dis_act_ = NULL;
727  }
728  } else if (act) {
729  if (bi_->dis_pyact_) {
730  hoc_obj_unref(bi_->dis_pyact_);
731  bi_->dis_pyact_ = NULL;
732  }
733  if (bi_->dis_act_) {
734  *bi_->dis_act_ = act;
735  } else {
736  bi_->dis_act_ = new CopyString(act);
737  }
738  }
739  if ((bi_->dis_act_ || bi_->dis_pyact_) && has_window()) {
741  new BoxDismiss(window(), bi_->dis_act_, this, bi_->dis_pyact_));
742  }
743 }
744 
745 void OcBox::save(ostream& o) {
746  char buf[256];
747  if (bi_->save_action_ || bi_->save_pyact_) {
748  if (bi_->save_action_ && strcmp(bi_->save_action_->string(), "") == 0) {
749  return;
750  }
751  if (has_window()) {
752  sprintf(buf, "\n//Begin %s", window()->name());
753  o << buf << endl;
754  }
755  o << "{" << endl;
756  bi_->o_ = &o;
757  if (bi_->save_pyact_) {
758  HocCommand hc(bi_->save_pyact_);
759  hc.execute();
760  } else {
761  HocCommand hc(bi_->save_action_->string(), bi_->keep_ref_);
762  hc.execute();
763  }
764  bi_->o_ = NULL;
765  } else {
766  if (bi_->type_ == H) {
767  o << "{\nocbox_ = new HBox()" << endl;
768  } else {
769  o << "{\nocbox_ = new VBox()" << endl;
770  }
771  o << "ocbox_list_.prepend(ocbox_)" << endl;
772  o << "ocbox_.intercept(1)\n}" << endl;
773  long i, cnt = bi_->ocglyph_list_->count();
774  for (i = 0; i < cnt; ++i) {
775  ((OcGlyph*) bi_->ocglyph_list_->component(i))->save(o);
776  }
777  o << "{\nocbox_ = ocbox_list_.object(0)" << endl;
778  o << "ocbox_.intercept(0)" << endl;
779  }
780  if (has_window()) {
781 #if defined(WIN32)
782  const char* cp1;
783  if (strchr(window()->name(), '"')) {
784  cp1 = "Neuron";
785  } else {
786  cp1 = window()->name();
787  }
788  sprintf(buf,
789  "ocbox_.map(\"%s\", %g, %g, %g, %g)\n}",
790  cp1,
791 #else
792  sprintf(buf,
793  "ocbox_.map(\"%s\", %g, %g, %g, %g)\n}",
794  window()->name(),
795 #endif
796  window()->save_left(),
797  window()->save_bottom(),
798 #if MAC
799  window()->canvas()->width(),
800  window()->canvas()->height());
801 #else
802  window()->width(),
803  window()->height());
804 #endif
805  o << buf << endl;
806  } else {
807  o << "ocbox_.map()\n}" << endl;
808  }
809  if (bi_->oc_ref_) {
810  sprintf(buf, "%s = ocbox_", hoc_object_pathname(bi_->oc_ref_));
811  o << buf << endl;
812  o << "ocbox_list_.remove(0)" << endl;
813  }
814  o << "objref ocbox_" << endl;
815  if (bi_->save_action_ && has_window()) {
816  sprintf(buf, "//End %s\n", window()->name());
817  o << buf << endl;
818  }
819 }
820 
821 
822 void OcBox::no_parents() {
823  // printf("OcBox::no_parents()\n");
824  if (bi_->keep_ref_) {
825  // printf("OcBox::no_parents unreffing %s\n", hoc_object_name(bi_->keep_ref_));
826  hoc_obj_unref(bi_->keep_ref_);
827  bi_->keep_ref_ = NULL;
828  }
829 }
830 
831 void OcBox::keep_ref(Object* ob) {
832  hoc_obj_ref(ob);
833  if (bi_->keep_ref_) {
834  hoc_obj_unref(bi_->keep_ref_);
835  }
836  bi_->keep_ref_ = ob;
837 }
838 
840  return bi_->keep_ref_;
841 }
842 
843 #endif /* HAVE_IV */
#define InputHandler
Definition: _defines.h:151
#define Patch
Definition: _defines.h:201
#define Background
Definition: _defines.h:43
#define ScrollBox
Definition: _defines.h:253
#define Placement
Definition: _defines.h:206
#define Coord
Definition: _defines.h:19
#define Layout
Definition: _defines.h:160
#define WidgetKit
Definition: _defines.h:331
#define GlyphIndex
Definition: _defines.h:23
#define Event
Definition: _defines.h:107
#define PolyGlyph
Definition: _defines.h:207
#define LayoutKit
Definition: _defines.h:161
#define Glyph
Definition: _defines.h:132
#define CopyString
Definition: _defines.h:2
short index
Definition: cabvars.h:10
short type
Definition: cabvars.h:9
void span(Coord)
Definition: geometry.h:269
virtual const char * name() const
virtual void dismiss()
virtual void replace_dismiss_action(WinDismiss *)
Definition: ocbox.h:11
OcBoxImpl * bi_
Definition: ocbox.h:37
OcBox(int type, int frame=INSET, bool scroll=false)
virtual void premap()
@ V
Definition: ocbox.h:13
@ H
Definition: ocbox.h:13
virtual void box_append(OcGlyph *)
virtual void no_parents()
virtual void dismiss_action(const char *, Object *pyact=NULL)
virtual void adjuster(Coord natural)
void keep_ref(Object *)
bool dismissing()
virtual void adjust(Coord natural, int)
virtual ~OcBox()
bool full_request()
Object * keep_ref()
virtual void save(ostream &)
virtual void save_action(const char *, Object *)
@ INSET
Definition: ocbox.h:14
virtual void intercept(bool)
OcGlyphContainer * parent_
Definition: ocglyph.h:57
virtual void request(Requisition &) const
virtual PrintableWindow * window()
virtual bool has_window()
virtual void def_size(Coord &w, Coord &h) const
Definition: ivoc.h:36
void notify()
static OcGlyphContainer * intercept(OcGlyphContainer *)
virtual Coord save_left() const
virtual Coord save_bottom() const
virtual void map()
void stretch(Coord)
Definition: geometry.h:237
void shrink(Coord)
Definition: geometry.h:239
void natural(Coord)
Definition: geometry.h:235
const Requirement & x_requirement() const
Definition: geometry.h:249
const Requirement & y_requirement() const
Definition: geometry.h:250
virtual void ref() const
Definition: resource.cpp:47
virtual void unref() const
Definition: resource.cpp:52
Definition: string.h:34
const char * string() const
Definition: string.h:139
virtual void execute()
static Frame * frame
Definition: code.cpp:161
void execute(Inst *p)
Definition: code.cpp:2661
double t
Definition: cvodeobj.cpp:59
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
double chkarg(int, double low, double high)
Definition: code2.cpp:638
#define c
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:754
@ Dimension_Y
Definition: geometry.h:43
@ Dimension_X
Definition: geometry.h:43
unsigned int DimensionName
Definition: geometry.h:40
char buf[512]
Definition: init.cpp:13
char * hoc_object_pathname(Object *ob)
Definition: hoc_oop.cpp:1794
int hoc_is_object_arg(int narg)
Definition: code.cpp:756
void hoc_assign_str(char **cpp, const char *buf)
Definition: code.cpp:2350
int hoc_is_double_arg(int narg)
Definition: code.cpp:744
void hoc_obj_ref(Object *obj)
Definition: hoc_oop.cpp:1810
double * hoc_pgetarg(int narg)
Definition: code.cpp:1623
void hoc_obj_unref(Object *obj)
Definition: hoc_oop.cpp:1828
char ** hoc_pgargstr(int narg)
Definition: code.cpp:1599
#define TRY_GUI_REDIRECT_ACTUAL_DOUBLE(name, obj)
Definition: gui-redirect.h:71
#define TRY_GUI_REDIRECT_NO_RETURN(name, obj)
Definition: gui-redirect.h:47
#define TRY_GUI_REDIRECT_OBJ(name, obj)
Definition: gui-redirect.h:12
#define assert(ex)
Definition: hocassrt.h:32
#define IFGUI
Definition: hocdec.h:372
#define getarg
Definition: hocdec.h:15
#define gargstr
Definition: hocdec.h:14
#define ENDGUI
Definition: hocdec.h:373
Object ** hoc_objgetarg(int)
Definition: code.cpp:1587
int ifarg(int)
Definition: code.cpp:1581
#define MAC
Definition: matlab.h:50
#define v
Definition: md1redef.h:4
#define i
Definition: md1redef.h:12
char * name
Definition: init.cpp:16
static List * ba_list_
Definition: nocpout.cpp:172
size_t p
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
Definition: hoc_oop.cpp:1560
static realtype b_
static double adjuster(void *v)
Definition: ocbox.cpp:289
const char * pwm_session_filename()
void VBox_reg()
Definition: ocbox.cpp:450
static Member_func members[]
Definition: ocbox.cpp:417
static double adjust(void *v)
Definition: ocbox.cpp:298
double(* nrnpy_object_to_double_)(Object *)
Definition: xmenu.cpp:14
static double dialog(void *v)
Definition: ocbox.cpp:224
static void destruct(void *v)
Definition: ocbox.cpp:154
static double unmap(void *v)
Definition: ocbox.cpp:248
static double b_size(void *v)
Definition: ocbox.cpp:327
static double full_request(void *v)
Definition: ocbox.cpp:312
static double map(void *v)
Definition: ocbox.cpp:192
static double ses_pri(void *v)
Definition: ocbox.cpp:180
void HBox_reg()
Definition: ocbox.cpp:446
static double dismiss_action(void *v)
Definition: ocbox.cpp:400
static void * vcons(Object *)
Definition: ocbox.cpp:120
static double save(void *v)
Definition: ocbox.cpp:346
int hoc_return_type_code
Definition: code.cpp:42
static double ismapped(void *v)
Definition: ocbox.cpp:275
static double ref(void *v)
Definition: ocbox.cpp:383
static double intercept(void *v)
Definition: ocbox.cpp:168
static void * hcons(Object *)
Definition: ocbox.cpp:139
virtual void press(const Event &e)
Definition: ocinput.h:29
virtual void drag(const Event &e)
Definition: ocinput.h:32
virtual void release(const Event &e)
Definition: ocinput.h:35
#define g
Definition: passive0.cpp:21
#define e
Definition: passive0.cpp:22
o
Definition: seclist.cpp:175
#define cnt
Definition: spt2queue.cpp:19
#define NULL
Definition: sptree.h:16
Definition: hocdec.h:227