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