2 #include <../../nrnconf.h> 16 char** (*nrnpy_gui_helper3_str_)(
const char*
name,
Object* obj,
int handle_strptr) =
NULL;
18 #if HAVE_IV // to end of file except for a few small fragments. 27 #include <InterViews/box.h> 28 #include <IV-look/kit.h> 29 #include <InterViews/event.h> 30 #include <InterViews/layout.h> 31 #include <InterViews/style.h> 32 #include <InterViews/background.h> 33 #include <InterViews/border.h> 34 #include <InterViews/dialog.h> 35 #include <InterViews/printer.h> 37 #include <InterViews/transformer.h> 38 #include <InterViews/patch.h> 39 #include <InterViews/color.h> 40 #include <InterViews/telltale.h> 41 #include <InterViews/hit.h> 43 #include <InterViews/display.h> 63 virtual ~PanelInputHandler();
66 static bool has_old_focus() {
bool old = sema_; sema_ =
false;
return old; }
76 bool PanelInputHandler::sema_ =
false;
80 PanelInputHandler::~PanelInputHandler(){
83 const Event*
e = h.event();
84 if (focus_ && e && e->type() ==
Event::key && focus_->handler()) {
85 h.target(depth,
this, 0, focus_->handler());
87 InputHandler::pick(
c, a, depth, h);
91 if (focus_ && focus_ != h) {
100 InputHandler::focus(h);
116 virtual ~ValEdLabel();
121 static const Color* color_;
126 const Color* ValEdLabel::color_;
131 color_ =
Color::lookup(Session::instance()->default_display(),
138 ValEdLabel::~ValEdLabel() {
144 MonoGlyph::draw(
c, a);
146 void ValEdLabel::state(
bool s) {
157 static void hoc_ivpanelPlace(
Coord,
Coord,
int scroll = -1);
159 static String* xvalue_format;
161 #define Editor_Default "DefaultValueEditor" 162 #define Editor_Stepper "DefaultValueEditor" 202 bool add2menubar =
false;
261 char *s1, *s2 = (
char *)0;
290 char *s1, *s2 = (
char *)0;
312 char *s1, *s2 = (
char *)0;
323 activate = (
chkarg(3, 0, 1) != 0.);
338 static void hoc_xvalue_helper() {
IFGUI 368 bool canRun=
false, usepointer=
false;
402 bool usepointer =
false;
413 static void hoc_xpvalue_helper() {
IFGUI 456 hoc_xpvalue_helper();
489 float low=0, high=100;
500 resolution = (high - low)/100.;
524 hoc_ivslider(pval, low, high, resolution, nsteps, send, vert, slow, pyvar, pysend);
531 class HocButton :
public Button {
534 virtual ~HocButton();
535 static HocButton* instance(
const char*,
Action*);
542 l_ = WidgetKit::instance()->label(
text);
546 HocButton* HocButton::instance(
const char*
s,
Action* a) {
547 Button* b = WidgetKit::instance()->push_button(
s, a);
549 HocButton* hb =
new HocButton(
564 static HocPanelList* hoc_panel_list;
565 static HocPanel* curHocPanel;
567 static void checkOpenPanel() {
577 bool isEmpty() {
return l_.count() == 0; }
579 void pop() {
if (l_.count()) {l_.item(0)->unref(); l_.remove(0); }}
580 Menu* top() {
return (l_.count()) ? l_.item(0)->menu() :
NULL; }
581 HocItem* hoc_item() {
return (l_.count()) ? l_.item(0) :
NULL; }
586 void MenuStack::push(
HocMenu* m) {
590 void MenuStack::clean() {
591 for (
long i = 0;
i < l_.count();
i++) {
596 static MenuStack* menuStack;
597 static Menu* hocmenubar;
602 virtual ~OcTelltaleGroup();
611 OcTelltaleGroup::OcTelltaleGroup() {
615 OcTelltaleGroup::~OcTelltaleGroup() {
618 if (t != current_ && t->test(TelltaleState::is_chosen)) {
619 previous_ = current_;
625 if (previous_ == t) {
635 previous_->set(TelltaleState::is_chosen,
true);
638 current_->set(TelltaleState::is_chosen,
false);
643 class HocRadioAction :
public HocAction {
645 HocRadioAction(
const char* action, OcTelltaleGroup*,
Object* pyact =
NULL);
646 virtual ~HocRadioAction();
649 OcTelltaleGroup* tg_;
652 HocRadioAction::HocRadioAction(
const char* action, OcTelltaleGroup* tg,
Object* pyact)
659 HocRadioAction::~HocRadioAction() {
672 OcTelltaleGroup* group() {
return g_; }
679 HocRadio::HocRadio() { g_ =
NULL; }
683 g_ =
new OcTelltaleGroup();
692 static HocRadio* hoc_radio;
696 hoc_radio =
new HocRadio();
699 fprintf(stderr,
"%s not closed\n", curHocPanel->getName());
703 curHocPanel->unref();
707 curHocPanel =
new HocPanel(
name, h);
715 curHocPanel->map_window(scroll);
716 curHocPanel->unref();
718 if (menuStack && !menuStack->isEmpty()) {
719 fprintf(stderr,
"%s menu not closed\n", menuStack->hoc_item()->getStr());
728 curHocPanel->left_ =
left;
729 curHocPanel->bottom_ = bottom;
736 if (menuStack && ! menuStack->isEmpty()) {
737 menuStack->top()->append_item(curHocPanel->menuItem(
name, action,
false, pyact));
739 curHocPanel->pushButton(
name, action,
false, pyact);
746 if (menuStack && ! menuStack->isEmpty()) {
747 menuStack->top()->append_item(curHocPanel->menuStateItem(pd,
name, action, pyvar, pyact));
749 curHocPanel->stateButton(pd,
name, action, style, pyvar, pyact);
755 if (!hoc_radio->group()) {
758 if (menuStack && ! menuStack->isEmpty()) {
759 menuStack->top()->append_item(curHocPanel->menuItem(
name, action,
activate, pyact));
767 menuStack =
new MenuStack();
775 curHocPanel->itemAppend(
"xmenu()");
782 menuStack =
new MenuStack();
788 m->
item()->action(hma);
795 curHocPanel->valueEd(
name, variable,
NULL,
false,
812 bool deflt,
bool canRun,
bool usepointer,
Object* pyvar,
Object* pyact)
815 deflt, canRun, usepointer);
826 if (!pvar && !pyvar) {
833 if (!xtra) { xtra = s ? s->
extra :
NULL; }
834 curHocPanel->valueEd(
name, variable, action, canrun,
835 pvar, deflt,
false, xtra, pyvar, pyact);
842 curHocPanel->valueEd(
name, 0, action, canRun, pd, deflt,
false, extra);
848 curHocPanel->label(s);
854 curHocPanel->var_label(
s, pyvar);
859 float resolution,
int nsteps,
const char*
s,
bool vert,
862 curHocPanel->slider(pd, low, high, resolution, nsteps,
s, vert, slow, pyvar, pyact);
865 static char* hideQuote(
const char*
s) {
866 static char buf[200];
871 if (s)
for (cp1=s; *cp1; cp1++, cp2++) {
881 static void saveMenuFile() {
884 void HocPanel::save_all(ostream&) {
885 if (!hoc_panel_list)
return;
890 cnt = hoc_panel_list->count();
891 if (hoc_panel_list)
for (i = 0; i <
cnt; ++
i) {
892 hoc_panel_list->item(i)->data_path(data_paths,
true);
895 if (hoc_panel_list)
for (i = 0; i <
cnt; ++
i) {
896 hoc_panel_list->item(i)->data_path(data_paths,
false);
901 void HocPanel::update_ptrs() {
902 if (!hoc_panel_list)
return;
904 for (i=0; i < hoc_panel_list->count(); ++
i) {
905 HocUpdateItemList& ul = hoc_panel_list->item(i)->elist_;
906 for (j=0; j < ul.count(); ++
j) {
907 ul.item(j)->update_ptrs();
913 void HocPanel::mac_menubar() {
916 printf(
"menubar 0 %s\n", getName());
917 mac_menubar(mindex, i, 0);
920 void HocPanel::mac_menubar(
int& mindex,
int&
i,
int m) {
923 while (
i < ilist_.count()) {
924 mr = ilist_.item(
i)->mac_menubar(mindex, m, mi);
928 mac_menubar(mindex,
i, mr);
937 void HocPanel::map_window(
int scroll) {
940 if (1 || maxcnt == -1) {
942 Style*
s = WidgetKit::instance()->style();
943 s->find_attribute(
"panel_scroll", maxcnt);
945 if ((scroll == -1 && box_->count() > maxcnt) || scroll == 1) {
948 ScrollBox* vsb = lk.vscrollbox(box_->count());
949 while(box_->count()) {
950 vsb->append(box_->component(0));
963 w->style(
new Style(WidgetKit::instance()->style()));
964 w->style()->attribute(
"name", getName());
973 static void var_freed(
void* pd,
int size) {
974 if (hoc_panel_list)
for (
long i = hoc_panel_list->count() - 1;
i >= 0; --
i) {
975 hoc_panel_list->item(
i)->check_valid_pointers(pd, size);
990 body(ih_ =
new PanelInputHandler(
994 lk.hflexible(box_,
fil, 0), 3
1002 if (!hoc_panel_list) {
1003 hoc_panel_list =
new HocPanelList;
1007 hoc_panel_list->append(
this);
1014 HocPanel::~HocPanel() {
1017 for (i = 0; i < ilist_.count(); i++) {
1018 ilist_.item(i)->HocItem::unref();
1020 for (i = 0; i < elist_.count(); i++) {
1021 elist_.item(i)->HocItem::unref();
1023 for (i=0; i < hoc_panel_list->count(); ++
i) {
1024 if (hoc_panel_list->item(i) ==
this) {
1025 hoc_panel_list->remove(i);
1029 ilist_.remove_all();
1030 elist_.remove_all();
1037 HocPanel::keep_updated(
this,
false);
1043 HocUpdateItemList* HocPanel::update_list_;
1045 void HocPanel::keep_updated() {
1047 if (update_list_ && (++cnt%10 == 0)) {
1048 long i, cnt = update_list_->count();
1049 if (cnt)
for(i=0; i <
cnt; ++
i) {
1050 update_list_->item(i)->update_hoc_item();
1055 if (!update_list_) {
1056 update_list_ =
new HocUpdateItemList();
1059 update_list_->append(hui);
1061 for (
long i=0;
i < update_list_->count(); ++
i) {
1062 if (update_list_->item(
i) == hui) {
1063 update_list_->remove(
i);
1070 void HocPanel::paneltool(
const char*
name,
const char* proc,
const char* selact,
ScenePicker* sp,
Object* pycallback,
Object* pyselact) {
1072 HocCommandTool* hct =
new HocCommandTool(hc);
1074 if (selact || pyselact) {
1077 if (curHocPanel && (!menuStack || menuStack->isEmpty())) {
1079 curHocPanel->box()->append(b);
1085 void HocPanel::itemAppend(
const char* str) {
1086 item_append(
new HocItem(str));
1094 const char* HocPanel::getName() {
1095 return ilist_.item(0)->getStr();
1098 HocItem* HocPanel::hoc_item() {
1099 return ilist_.item(0);
1102 void HocPanel::pushButton(
const char*
name,
const char* action,
bool activate,
Object* pyact) {
1103 if (hoc_radio->group()) {
1104 HocRadioAction* a =
new HocRadioAction(action, hoc_radio->group(), pyact);
1105 Button* b = WidgetKit::instance()->radio_button(hoc_radio->group(),
1111 tts->set(TelltaleState::is_chosen,
true);
1112 hoc_radio->group()->update(tts);
1116 box()->append(WidgetKit::instance()->push_button(
name, a));
1131 nrn_assert(snprintf(buf, 200,
"xbutton(\"%s\",\"%s\")", getStr(), hideQuote(
a_->name())) < 200);
1136 int HocPushButton::mac_menubar(
int&,
int m,
int mi) {
1137 printf(
"button item %d in menu %d \"%s\", \"%s\"\n", mi, m, getStr(), hideQuote(
a_->name()));
1152 nrn_assert(snprintf(buf, 200,
"xradiobutton(\"%s\",\"%s\")", getStr(), hideQuote(
a_->name())) < 200);
1157 int HocRadioButton::mac_menubar(
int&,
int m,
int mi) {
1158 printf(
"radio item %d in menu %d \"%s\", \"%s\"\n", mi, m, getStr(), hideQuote(
a_->name()));
1163 void HocPanel::label(
const char*
name) {
1165 LayoutKit::instance()->margin(
1166 WidgetKit::instance()->label(name), 3
1172 void HocPanel::var_label(
char**
name,
Object* pyvar) {
1180 void HocPanel::slider(
double* pd,
float low,
float high,
1181 float resolution,
int nsteps,
1184 slow, pyvar, pysend);
1188 wk->begin_style(
"SlowSlider");
1193 WidgetKit::instance()->vscroll_bar(s->
adjustable())
1199 WidgetKit::instance()->hscroll_bar(s->
adjustable())
1211 HocMenu* HocPanel::menu(
const char*
name,
bool add2menubar) {
1213 Menu* m = wk->pulldown();
1216 if (menuStack->isEmpty()) {
1227 box()->append(lk->hbox(m0,lk->hglue()));
1229 mi = wk->menubar_item(
name);
1230 m0->append_item(mi);
1231 hm =
new HocMenu(
name, m, mi, hoc_item(), add2menubar);
1234 menuStack->top()->append_item(mi);
1235 hm =
new HocMenu(
name, m, mi, menuStack->hoc_item());
1244 if (hoc_radio->group()) {
1245 HocRadioAction* a =
new HocRadioAction(act, hoc_radio->group(), pyact);
1251 tts->set(TelltaleState::is_chosen,
true);
1252 hoc_radio->group()->update(tts);
1266 add2menubar_ = add2menubar;
1274 sprintf(buf,
"xmenu(\"%s\", %d)", getStr(), add2menubar_);
1279 int HocMenu::mac_menubar(
int& mindex,
int m,
int mi) {
1281 printf(
"menu %d is item %d in %d %s\n", mindex, mi, m, getStr());
1286 static Coord xvalue_field_size;
1288 void HocPanel::valueEd(
const char* prompt,
Object* pyvar,
Object* pyact,
1289 bool canrun,
bool deflt,
bool keep_updated)
1291 valueEd(prompt,
NULL,
NULL, canrun,
NULL, deflt, keep_updated,
NULL, pyvar, pyact);
1294 void HocPanel::valueEd(
const char*
name,
const char* variable,
const char* action,
bool canrun,
1298 if (pyact || action) {
1311 vel =
new ValEdLabel(WidgetKit::instance()->label(nu));
1313 vel =
new ValEdLabel(WidgetKit::instance()->label(
name));
1317 prompt = WidgetKit::instance()->default_button(vel, act);
1319 prompt = WidgetKit::instance()->push_button(vel, act);
1321 vel->tts(prompt->state());
1326 name, variable, vel,
1327 act, pd, canrun, hoc_item(), pyvar);
1330 }
else if (keep_updated) {
1332 act, pd, hoc_item(), pyvar);
1335 act, pd, canrun, hoc_item(), pyvar);
1344 Style*
s = WidgetKit::instance()->style();
1345 if(!s->find_attribute(
"stepper_size", fct)){
1349 box()->append(lk->hbox(
1350 lk->vcenter(prompt),
1352 lk->vcenter(lk->h_fixed_span(fe->
field_editor(), xvalue_field_size)),
1353 lk->vcenter(lk->fixed(fe->
stepper(), (
int) fct, (
int) fct ))
1356 box()->append(lk->hbox(
1358 lk->h_fixed_span(fe->
field_editor(), xvalue_field_size),
1367 last_fe_constructed_ = fe;
1376 void HocPanel::write(ostream&
o) {
1381 sprintf(buf,
"xpanel(\"%s\", %d)", getName(), horizontal_);
1383 for (i = 1; i < ilist_.count(); i++) {
1384 ilist_.item(i)->write(o);
1388 window()->save_left(), window()->save_bottom());
1391 o <<
"xpanel()" << endl;
1395 void HocPanel::item_append(
HocItem* hi) {
1408 o << str_.string() << endl;
1412 int HocItem::mac_menubar(
int&,
int m,
int mi) {
1413 if (strcmp(getStr(),
"xmenu()") == 0) {
1414 printf(
"end menu %d\n", m);
1417 printf(
"invalid menuitem %s\n", getStr());
1424 return str_.string();
1433 char buf[200], *c2 =
buf;
1435 for (c1 = getStr(); *c1; ++c1) {
1442 sprintf(path,
"%s %s", child, buf);
1447 help_parent_->help(path);
1458 sprintf(buf,
"xlabel(\"%s\")", hideQuote(getStr()));
1463 extern void purify_watch_rw_4(
char**);
1474 (*nrnpy_guigetstr)(pyvar_, &cp_);
1479 p_ =
new Patch(LayoutKit::instance()->margin(
1480 WidgetKit::instance()->label(cp_), 3
1493 if (cp_) {
delete [] cp_; }
1498 if (variable_ && cpp_) {
1500 sprintf(buf,
"xvarlabel(%s)", variable_->string());
1503 o <<
"xlabel(\"<can't retrieve>\")" << endl;
1511 LayoutKit::instance()->margin(
1512 WidgetKit::instance()->label(cp_), 3
1525 LayoutKit::instance()->margin(
1526 WidgetKit::instance()->label(cp_), 3
1537 LayoutKit::instance()->margin(
1538 WidgetKit::instance()->label(
"Free'd"), 3
1557 while (hm_->menu()->item_count()) {
1558 hm_->menu()->remove_item(0);
1563 menuStack->push(hm_);
1569 hm_->item()->menu(hm_->menu());
1577 }
else if (action && action[0] !=
'\0') {
1617 return action_->name();
1652 if (fe_->active()) {
1653 fe_->field_editor()->parent()->focus(
NULL);
1666 accept(fe_->field_editor());
1669 class HocDefaultCheckbox :
public Button {
1673 virtual ~HocDefaultCheckbox();
1686 HocDefaultCheckbox::~HocDefaultCheckbox() { }
1693 k.begin_style(
"ToggleButton",
"Button");
1695 TelltaleState::is_enabled | TelltaleState::is_toggle
1697 g = k.check_box_look(
NULL, t);
1699 HocDefaultCheckbox*
cb =
new HocDefaultCheckbox(dve, g, s, t,
NULL);
1709 dve_->def_change(e.pointer_root_x(), e.pointer_root_y());
1719 ValEdLabel* prompt,
HocValAction* a,
double* pd,
bool canrun,
1723 checkbox_ = HocDefaultCheckbox::instance(
this);
1728 deflt_ = most_recent_ = get_val();
1740 double x = get_val();
1742 char form[200],
buf[200];
1743 sprintf(form,
"Permanently replace default value %s with %s",
1745 sprintf(buf, form, deflt_, x);
1757 bool same = (
hoc_ac_ == deflt_);
1758 bool chosen = t->test(TelltaleState::is_chosen);
1759 if (same && chosen) {
1760 t->set(TelltaleState::is_chosen,
false);
1764 t->set(TelltaleState::is_chosen,
true);
1775 checkbox_->state()->set(TelltaleState::is_chosen,
1776 !checkbox_->state()->test(TelltaleState::is_chosen));
1780 bool chosen = checkbox_->state()->test(TelltaleState::is_chosen);
1782 if (most_recent_ != deflt_) {
1783 set_val(most_recent_);
1786 double x = get_val();
1804 HocPanel::keep_updated(
this,
true);
1808 HocPanel::keep_updated(
this,
false);
1814 :
FieldSEditor(
"", WidgetKit::instance(), Session::instance()->style(), a->
fea()) {
1826 static void set_format() {
1828 if (!xvalue_format) {
1829 xvalue_format =
new String(
"%.5g");
1830 WidgetKit::instance()->style()->find_attribute(
"xvalue_format",
1833 sprintf(buf, xvalue_format->
string(), -8.888888888888888e-18);
1834 Glyph*
g = WidgetKit::instance()->label(buf);
1841 Style*
s = WidgetKit::instance()->style();
1842 if(!s->find_attribute(
"xvalue_field_size_increase", fct)){
1851 if (!xvalue_format) {
1858 for (cp = buf; *cp; ++cp) {
1865 if (*cp >=
'1' && *cp <=
'9') {
1876 sscanf(buf,
"%lf", &y);
1885 if (!xvalue_format) {
1896 domain_limits_ =
NULL;
1905 }
else if (variable) {
1908 if (sym && sym->
extra) {
1946 Glyph* l = WidgetKit::instance()->label(*fe_->text());
1955 (*nrnpy_guisetval)(pyvar_, x);
1962 }
else if (variable_){
1963 sprintf(buf,
"%s = hoc_ac_\n", variable_->string()); oc.
run(buf);
1973 }
else if (variable_) {
1975 sprintf(buf,
"hoc_ac_ = %s\n", variable_->string()); oc.
run(buf);
1989 sprintf(buf,
"hoc_ac_ = %s\n", fe_->text()->string()); oc.
run(buf);
1993 prompt_->state(
false);
2000 }
else if (variable_) {
2002 variable_->string(), fe_->text()->string());
2004 sprintf(buf,
"// %p pointer set to %s\n",
2005 pval_, fe_->text()->string());
2019 }
else if (variable_) {
2021 sprintf(buf,
"hoc_ac_ = %s\n", variable_->string());
2022 if (oc.
run(buf, 0)) {
2023 strcpy(buf,
"Doesn't exist");
2030 if (strcmp(buf, fe_->text()->string()) != 0) {
2039 sprintf(buf,
"hoc_ac_ = %s\n", variable_->string()); oc.
run(buf);
2042 sprintf(buf,
"/* don't know the hoc path to %g", *pval_);
2045 sprintf(buf,
"/* variable freed */");
2056 nrn_assert(snprintf(buf, 200,
"xvalue(\"%s\",\"%s\", %d,\"%s\", %d, %d )", getStr(),
2057 variable_->string(), hoc_default_val_editor(),
2058 hideQuote(action_->name()),
2059 (
int)canrun_, usepointer) < 200);
2065 return variable_->string();
2075 sprintf(buf,
"hoc_ac_ = %s\n", variable()); oc.
run(buf);
2078 sprintf(buf,
"xvalue(\"%s\",\"%s\", 2 )", getStr(),
2084 bool unfocus =
false;
2085 if (!hve_->active_) {
2093 if (e.mapkey(buf, 1) > 0)
switch (buf[0]) {
2099 hve_->active_ =
false;
2100 hve_->updateField();
2101 hve_->active_ =
true;
2105 hve_->active_ =
false;
2106 hve_->updateField();
2107 hve_->active_ =
true;
2117 class HocEditorTempData {
2120 int sn(
const Event&);
2130 static HocEditorTempData etd;
2139 b_ = e.pointer_button();
2147 int HocEditorTempData::sn(
const Event&) {
2149 float xnew =
e.pointer_x();
2150 float ynew =
e.pointer_y();
2156 sn_ = ( ((xnew -
x_)*xd_ + (ynew -
y_)*yd_ >= 0.)) ? sn_ : -sn_;
2201 const char*
s =
text()->string();
2205 if (i == strlen(buf)) {
2210 if (isdigit(buf[i])) {
2211 buf[
i] = (((buf[
i] -
'0') + sn + 100)%10) +
'0';
2212 if (sn == 1 && buf[i] !=
'0') {
2214 }
else if (sn == -1 && buf[i] !=
'9') {
2221 if (buf[0] ==
'-') {
2253 if (!hve_->active_) {
2255 hve_->prompt_->state(
true);
2256 hve_->active_ =
true;
2259 return InputHandler::focus_in();
2264 if (hve_->active_) {
2265 hve_->active_ =
false;
2267 hve_->prompt_->state(
false);
2271 if (PanelInputHandler::has_old_focus()) {
2273 hve_->exec_action();
2282 if (hoc_panel_list)
for (
long i = hoc_panel_list->count() - 1;
i >= 0; --
i) {
2283 hoc_panel_list->item(
i)->notifyHocValue();
2288 void HocPanel::notifyHocValue() {
2289 for (
long i = elist_.count() - 1;
i >= 0; --
i) {
2290 elist_.item(
i)->update_hoc_item();
2294 void HocPanel::check_valid_pointers(
void*
v,
int size) {
2295 for (
long i = elist_.count() - 1;
i >= 0; --
i) {
2296 elist_.item(
i)->check_pointer(
v, size);
2302 double* pd = (
double*)
v;
2304 if (pd != pval_)
return;
2306 if (pval_ < pd || pval_ >= pd + size)
return;
2312 char** cpp = (
char**)
v;
2319 for (
long i = elist_.count() - 1;
i >= 0; --
i) {
2320 elist_.item(
i)->data_path(hdp, append);
2338 if (cpp_ && !variable_) {
2350 class StepperMenuAction :
public Action {
2352 StepperMenuAction(
bool,
double);
2353 virtual ~StepperMenuAction();
2363 virtual ~StepperMenu();
2366 virtual bool event(
Event&);
2376 StepperMenuAction::StepperMenuAction(
bool b,
double x) {
2380 StepperMenuAction::~StepperMenuAction() {
2385 StepperMenu::StepperMenu() {
2392 m->action(
new StepperMenuAction(
false, 0));
2395 m->action(
new StepperMenuAction(
true, 10));
2398 m->action(
new StepperMenuAction(
true,
pow(10., .1)));
2401 m->action(
new StepperMenuAction(
true,
exp(1.)));
2404 m->action(
new StepperMenuAction(
true,
exp(.1)));
2407 m->action(
new StepperMenuAction(
true, 2));
2410 m->action(
new StepperMenuAction(
true,
pow(2., .1)));
2412 for (
double x = 1000 ; x > .0005; x /= 10.) {
2415 m->action(
new StepperMenuAction(
false, x));
2419 StepperMenu::~StepperMenu() {
2421 bool StepperMenu::event(
Event&
e) {
2423 if (e.type() == Event::up) {
2429 class NrnUpDown :
public Glyph {
2431 static NrnUpDown* instance();
2432 virtual ~NrnUpDown();
2436 NrnUpDown(
const Color*);
2437 static NrnUpDown* instance_;
2438 const Color* color_;
2441 NrnUpDown* NrnUpDown::instance_;
2448 NrnUpDown::~NrnUpDown() {
2452 NrnUpDown* NrnUpDown::instance() {
2454 instance_ =
new NrnUpDown(WidgetKit::instance()->foreground());
2475 Coord x = (x1 + x2)*.5;
2476 Coord y = (y1 + y2)*.5;
2479 c->move_to(x1, y+1);
2481 c->line_to(x2, y+1);
2487 c->move_to(x1, y-1);
2489 c->line_to(x2, y-1);
2496 return WidgetKit::instance()->push_button_look(NrnUpDown::instance(), t);
2504 k.begin_style(
"UpMover",
"Button");
2506 g = up_down_mover_look(t);
2517 menu_ =
new StepperMenu();
2528 inc_ = default_inc_;
2529 menu_->active(
false);
2533 switch (e.pointer_button()) {
2535 case Event::middle :
2538 if (e.pointer_y() < (a.
bottom() + a.
top())*.5) {
2540 inc_ = 1./default_inc_;
2545 menu_->stepper(
this);
2551 menu_->active(
true);
2552 menu_->stepper(
this);
2574 if (menu_->active()) {
2575 menu_->active(
false);
2581 hve_->exec_action();
2585 menu_->active(
true);
2587 handler()->event(e);
2595 x = hve_->get_val();
2601 y = hve_->domain_limits(y);
2602 if ( steps_ > 0 && x*y <= 0.) {
2607 hve_->updateField();
2608 if (!geometric_ && ((++steps_)%20) == 0) {
2613 inc_ = default_inc_;
2616 inc_ = default_inc_;
2625 float resolution,
int nsteps,
2629 resolution_ = resolution;
2637 bv_->scroll_incr((high - low)/nsteps);
2660 static double last_send;
2662 double x = slider_val();
2666 (*nrnpy_guisetval)(pyvar_, x);
2672 while (
Coord(x) != last_send) {
2674 last_send =
Coord(x);
2690 variable_->string(), *pval_);
2692 sprintf(buf,
"// %p pointer set to %g\n",
2721 bool old = scrolling_;
2729 double* pd = (
double*)
v;
2731 if (pd != pval_)
return;
2733 if (pval_ < pd || pval_ >= pd + size)
return;
2739 if (!variable_ && pval_) {
2754 sprintf(buf,
"xslider(&%s, %g, %g, \"%s\", %d, %d)",
2755 variable_->string(),
2758 hideQuote(send_->name()),
2762 sprintf(buf,
"xslider(&%s, %g, %g, %d, %d)",
2763 variable_->string(),
2778 void HocPanel::stateButton(
double* pd,
const char*
name,
const char* action,
int style,
Object* pyvar,
Object* pyact) {
2783 button = WidgetKit::instance()->palette_button(
name,act);
2785 button = WidgetKit::instance()->check_box(
name,act);
2787 box()->append(button);
2820 if (variable_)
delete variable_;
2830 Glyph* l = WidgetKit::instance()->label(name_->string());
2837 return b_->state()->test(TelltaleState::is_chosen);
2843 b_->state()->set(TelltaleState::is_chosen, !chosen());
2848 if (chosen() !=
bool(*pval_)) {
2849 *pval_ = double(chosen());
2855 (*nrnpy_guisetval)(pyvar_, double(chosen()));
2876 b_->state()->set(TelltaleState::is_chosen,
true);
2878 b_->state()->set(TelltaleState::is_chosen,
false);
2884 double* pd = (
double*)
v;
2886 if (pd != pval_)
return;
2888 if (pval_ < pd || pval_ >= pd + size)
return;
2895 if (!variable_ && pval_) {
2909 if (style_ == PALETTE) {
2910 sprintf(buf,
"xstatebutton(\"%s\",&%s,\"%s\")",
2912 variable_->string(),
2913 hideQuote(action_->name())
2916 sprintf(buf,
"xcheckbox(\"%s\",&%s,\"%s\")",
2918 variable_->string(),
2919 hideQuote(action_->name())
2932 MenuItem* HocPanel::menuStateItem(
double* pd,
const char*
name,
const char* action,
Object* pyvar,
Object* pyact) {
2934 MenuItem* mi = WidgetKit::instance()->check_menu_item(
name);
2971 if (variable_)
delete variable_;
2980 Glyph* l = WidgetKit::instance()->label(name_->string());
2987 return b_->state()->test(TelltaleState::is_chosen);
2994 b_->state()->set(TelltaleState::is_chosen, !chosen());
2999 if (chosen() !=
bool(*pval_)) {
3000 *pval_ = double(chosen());
3006 (*nrnpy_guisetval)(pyvar_, double(chosen()));
3027 b_->state()->set(TelltaleState::is_chosen,
true);
3029 b_->state()->set(TelltaleState::is_chosen,
false);
3035 double* pd = (
double*)
v;
3037 if (pd != pval_)
return;
3039 if (pval_ < pd || pval_ >= pd + size)
return;
3046 if (!variable_ && pval_) {
3061 sprintf(buf,
"xcheckbox(\"%s\",&%s,\"%s\")",
3063 variable_->string(),
3064 hideQuote(action_->name())
3078 hoc_xvalue_helper();
3080 hoc_xpvalue_helper();
3121 update_ptrs_helper(&pval_);
3125 update_ptrs_helper(&pval_);
3129 update_ptrs_helper(&pval_);
3133 update_ptrs_helper(&pval_);
virtual double domain_limits(double)
void hoc_ivfixedvalue(CChar *name, CChar *variable, bool deflt=false, bool usepointer=false)
virtual void update_hoc_item()
static MenuItem * menu_item(const char *)
void hoc_ivpvalue(CChar *name, double *, bool deflt=false, HocSymExtension *extra=NULL)
#define declarePtrList(PtrList, T)
virtual void val_inc(const Event &)
int hoc_is_str_arg(int narg)
virtual void data_path(HocDataPaths *, bool)
const char * name() const
virtual PrintableWindow * make_window(Coord left=-1, Coord bottom=-1, Coord width=-1, Coord height=-1)
String * retrieve(double *)
#define implementFieldSEditorCallback(T)
#define TRY_GUI_REDIRECT_NO_RETURN(name, obj)
static HocParmLimits limits[]
FieldSEditorAction * fea()
HocDefaultValEditor(const char *name, const char *variable, ValEdLabel *, HocValAction *, double *pd=0, bool canrun=false, HocItem *parent=NULL, Object *pyvar=NULL)
static bool equal(float x, float y, float e)
virtual void updateField()
Symbol * hoc_get_symbol(const char *var)
virtual void check_pointer(void *, int)
virtual void release(const Event &)
HocValAction(const char *action, Object *pyact=0)
static void help(const char *)
static void update(NrnThread *)
void hoc_ivlabel(CChar *)
virtual void help_parent(HocItem *)
virtual void help(const char *childpath=NULL)
HocAction(const char *action, Object *pyact=NULL)
void hoc_ivstatebutton(double *, CChar *name, CChar *action, int style, Object *pyvar=0, Object *pyact=0)
virtual void menu_up(Event &)
static MenuItem * radio_menu_item(TelltaleGroup *, const char *)
virtual void press(const Event &)
void update_ptrs_helper(double **)
char ** hoc_pgargstr(int narg)
static double anint(double)
virtual void press(const Event &)
const Requirement & x_requirement() const
virtual void check_pointer(void *, int vector_size)
static philox4x32_key_t k
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
void hoc_ivvarlabel(char **, Object *pyvar=0)
void notify_freed(void(*pf)(void *, int))
static void pr(N_Vector x)
void hoc_ivvalue_keep_updated(CChar *name, CChar *variable, Object *pyvar=0)
#define TRY_GUI_REDIRECT_ACTUAL_DOUBLE(name, obj)
HocVarLabel(char **, PolyGlyph *, Object *pyvar=NULL)
#define TRY_GUI_REDIRECT_DOUBLE_SEND_STRREF(name, obj)
virtual void update_hoc_item()
virtual void setlimits(float *)
static StepperMenu * menu()
static HocValStepper * instance(HocValEditor *)
virtual void press(const Event &)
HocValStepper(HocValEditor *, Glyph *, Style *, TelltaleState *)
double * hoc_pgetarg(int narg)
void hoc_ivvalue(CChar *name, CChar *variable, bool deflt=false, Object *pyvar=0)
virtual void drag(const Event &)
virtual void check_pointer(void *, int vector_size)
const char * string() const
void setFieldSEditor(HocValEditor *)
#define implementPtrList(PtrList, T)
FieldSEditor * field_editor()
int hoc_is_pdouble_arg(int narg)
Symbol * hoc_get_last_pointer_symbol()
void append(Item *ql, Item *q)
virtual ~HocDefaultValEditor()
#define declareFieldSEditorCallback(T)
virtual Stepper * stepper()
HocEditorForItem(HocValEditor *, HocValAction *)
virtual ~HocEditorForItem()
virtual void release(const Event &)
virtual InputHandler * focus_in()
#define TRY_GUI_REDIRECT_DOUBLE(name, obj)
virtual void selection(int &start, int &index) const
void hoc_ivbutton(CChar *name, CChar *action, Object *pyact=0)
virtual void keystroke(const Event &)
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
void hoc_obj_unref(Object *obj)
HocValEditor(const char *name, const char *variable, ValEdLabel *, HocValAction *, double *pd=0, bool canrun=false, HocItem *parent=NULL, Object *pvar=NULL)
static double remove(void *v)
virtual void exec_action()
static StepperMenu * menu_
virtual void data_path(HocDataPaths *, bool)
MenuItem * add_radio_menu(const char *, Action *, Menu *=NULL)
void hoc_execerror(const char *, const char *)
void hoc_ivpanel(CChar *, bool h=false)
virtual void update_ptrs()
void require_y(const Requirement &)
virtual void write(ostream &)
virtual ~HocValEditorKeepUpdated()
virtual void release(const Event &)
HocUpdateItem(const char *, HocItem *parent=NULL)
fprintf(stderr, "Don't know the location of params at %p\, pp)
virtual void write(ostream &)
static double restore(void *v)
virtual void unref() const
void hoc_obj_ref(Object *obj)
virtual void update_hoc_item()
#define FieldSEditorCallback(T)
void hoc_ivmenu(CChar *, bool add2menubar=false)
virtual void drag(const Event &)
virtual void write(ostream &)
virtual void update_ptrs()
OcSlider(double *, float low, float high, float resolution, int nsteps, const char *send_cmd, bool vert, bool slow=false, Object *pyvar=NULL, Object *pysend=NULL)
void hoc_ivslider(double *, float low=0, float high=100, float resolution=1, int steps=10, const char *send_cmd=NULL, bool vert=false, bool slow=false, Object *pyvar=0, Object *pyact=0)
void require_x(const Requirement &)
virtual void print(Printer *, const Allocation &) const
virtual void write(ostream &)
#define TRY_GUI_REDIRECT_OBJ(name, obj)
void hoc_ivpanelmap(int scroll=-1)
HocValEditorKeepUpdated(const char *name, const char *variable, ValEdLabel *, HocValAction *, double *, HocItem *parent=NULL, Object *pyvar=NULL)
void hoc_ivvaluerun(CChar *name, CChar *variable, CChar *action, bool deflt=false, bool canrun=false, bool usepointer=false, Object *pyvar=0, Object *pyact=0)
const char * variable() const
void accept(FieldSEditor *)
static double save(void *v)
void hoc_ivvaluerun_ex(CChar *name, CChar *var, double *pvar, Object *pyvar, CChar *action, Object *pyact, bool deflt=false, bool canrun=false, bool usepointer=false, HocSymExtension *extra=NULL)
virtual void data_path(HocDataPaths *, bool)
double * hoc_val_pointer(const char *s)
HocItem(const char *, HocItem *parent=NULL)
virtual double slider_val()
void hoc_ivpvaluerun(CChar *name, double *, CChar *action, bool deflt=false, bool canrun=false, HocSymExtension *extra=NULL)
double check_domain_limits(float *limits, double val)
void def_change(float, float)
virtual void update(Observable *)
Button * radio_button(const char *, Action *)
bool boolean_dialog(const char *label, const char *accept, const char *cancel, Window *w=NULL, Coord x=400., Coord y=400.)
virtual void write(ostream &)
Adjustable * adjustable()
int hoc_is_object_arg(int narg)
static double least(void *v)
virtual void write(ostream &)
void hoc_audit_command(const char *buf)
virtual void keystroke(const Event &)
void hoc_ivradiobutton(CChar *name, CChar *action, bool activate=false, Object *pyact=0)
virtual InputHandler * focus_in()
virtual void data_path(HocDataPaths *, bool)
void hoc_ivvarmenu(CChar *, CChar *, bool add2menubar=false, Object *pyvar=NULL)
int run(int argc, const char **argv)
Object ** hoc_objgetarg(int)
virtual void update_hoc_item()
double chkarg(int, double low, double high)
static double resolution(double)
double * nrn_recalc_ptr(double *)
virtual void check_pointer(void *, int)
static double active(void *v)
virtual void updateField()