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