1 #include <../../nrnconf.h>
9 #include <InterViews/dialog.h>
10 #include <InterViews/session.h>
11 #include <InterViews/display.h>
12 #include <InterViews/action.h>
13 #include <InterViews/layout.h>
14 #include <InterViews/style.h>
15 #include <InterViews/hit.h>
16 #include <InterViews/event.h>
17 #include <IV-look/kit.h>
18 #include <IV-look/dialogs.h>
22 #define Output IOS_OUT
23 #define Append IOS_APP | IOS_OUT
32 extern Object** (*nrnpy_gui_helper3_)(
const char*
name,
Object* obj,
int handle_strptr);
35 Style* s = Session::instance()->style();
36 if (s->value_is_on(
"dialog_spec_position")) {
37 s->find_attribute(
"dialog_left_position", x);
38 s->find_attribute(
"dialog_bottom_position", y);
46 return d->post_at_aligned(x, y, 0.0, 0.0);
48 if (x != 400. || y != 400.) {
49 return d->post_at_aligned(x, y, .5, .5);
51 Display* dis = Session::instance()->default_display();
52 return d->post_at_aligned(dis->width() / 2, dis->height() / 2, .5, .5);
63 class OcGlyphDialog:
public Dialog {
66 virtual ~OcGlyphDialog();
70 class DialogAction:
public Action {
72 DialogAction(
Dialog*,
bool);
73 virtual ~DialogAction();
82 DialogAction::DialogAction(
Dialog* d,
bool accept) {
86 DialogAction::~DialogAction() {
100 Dialog* d =
new Dialog(
k.outset_frame(l.margin(vbox, 5)), Session::instance()->style());
102 vbox->append(l.hcenter(
k.inset_frame(l.margin(
k.label(label), 10))));
103 vbox->append(l.hcenter(l.hbox(
k.push_button(accept,
new DialogAction(d,
true)),
105 k.push_button(cancel,
new DialogAction(d,
false)))));
109 ok = oc_post_dialog(d, x, y);
119 Dialog* d =
new Dialog(
k.outset_frame(l.margin(vbox, 5)), Session::instance()->style());
121 vbox->append(l.hcenter(
k.inset_frame(l.margin(
k.label(label), 10))));
122 vbox->append(l.hcenter(
k.push_button(
"Continue",
new DialogAction(d,
true))));
126 oc_post_dialog(d, x, y);
131 static bool ok_if_already_exists(
const char* s,
Window* w) {
137 static void open_fail(
const char* s,
Window* w,
const char* io) {
139 sprintf(
buf,
"Couldn't open %s for %sing", s, io);
145 if (obuf.open(s, Input)) {
147 if (!ok_if_already_exists(s, w)) {
152 if (obuf.open(s, Append)) {
155 open_fail(s, w,
"writ");
165 if (obuf.open(s, Input)) {
170 open_fail(s, w,
"read");
178 float x1 = x, y1 = y;
182 if (sscanf(
buf,
"%f%f", &x1, &y1) == 2) {
187 continue_dialog(
"Invalid entry: Enter pair of numbers separated by space.", w);
199 style->attribute(
"caption", caption);
206 ok = oc_post_dialog(d, x, y);
226 fe_->select(0,
fe_->text()->length());
240 WidgetKit& widgets = *WidgetKit::instance();
241 DialogKit& dialogs = *DialogKit::instance();
242 LayoutKit& layout = *LayoutKit::instance();
247 style->find_attribute(
"caption", caption);
248 style->find_attribute(
"accept",
accept);
249 style->find_attribute(
"cancel",
cancel);
252 g = widgets.inset_frame(layout.margin(layout.flexible(vb,
fil, 0), 10.0));
262 fd->
s_ = *fe->text();
264 vb->append(layout.flexible(widgets.label(caption)));
265 vb->append(layout.vglue(10));
268 vb->append(layout.vglue(10));
271 vb->append(layout.vglue(10));
274 hb->append(layout.hglue(20,
fil, 20));
275 hb->append(widgets.default_button(
accept,
new DialogAction(fd,
true)));
276 hb->append(layout.hglue(5));
277 hb->append(widgets.push_button(
cancel,
new DialogAction(fd,
false)));
278 hb->append(layout.hglue(20,
fil, 20));
335 class LabelChooserAction:
public Action {
337 LabelChooserAction(
GLabel*);
338 virtual ~LabelChooserAction();
351 style->attribute(
"caption", caption);
353 LabelChooserAction* lca =
new LabelChooserAction(gl);
354 Button* b =
k.check_box(
"vfixed", lca);
355 lca->state(b->state());
360 ok = oc_post_dialog(d, x, y);
368 LabelChooserAction::LabelChooserAction(
GLabel* gl) {
373 LabelChooserAction::~LabelChooserAction() {
381 ts_->set(TelltaleState::is_chosen,
false);
383 ts_->set(TelltaleState::is_chosen,
true);
388 if (ts_->test(TelltaleState::is_chosen)) {
390 gl_->vfixed(gl_->scale());
394 gl_->fixed(gl_->scale());
407 bool OcGlyph::dialog(
const char* label,
const char* accept,
const char* cancel) {
412 d_ =
new OcGlyphDialog(
k.outset_frame(l.margin(vbox, 5)), Session::instance()->style());
414 vbox->append(l.hcenter(l.hflexible(l.margin(
k.label(label), 10),
fil, 0)));
415 vbox->append(l.hcenter(
this));
416 vbox->append(l.hcenter(l.hflexible(l.hbox(
k.push_button(accept,
new DialogAction(
d_,
true)),
418 k.push_button(cancel,
new DialogAction(
d_,
false))),
422 ok = oc_post_dialog(
d_, 400., 400.);
431 OcGlyphDialog::~OcGlyphDialog() {}
433 const Event*
e = h.event();
438 body()->pick(
c, a, depth + 1, h);
442 Dialog::pick(
c, a, depth, h);
FieldDialog(Glyph *, Style *)
virtual void cancel(FieldEditor *)
virtual void accept(FieldEditor *)
virtual void dismiss(bool accept)
static FieldDialog * field_dialog_instance(const char *, Style *, Glyph *extra=NULL)
const String * text() const
static bool label_chooser(const char *, char *, GLabel *, Coord x=400., Coord y=400.)
virtual bool dialog(const char *label, const char *accept, const char *cancel)
bool dialog_dismiss(bool b)
virtual void unref() const
const char * string() const
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)
Object **(* nrnpy_gui_helper_)(const char *name, Object *obj)
double(* nrnpy_object_to_double_)(Object *)
void hoc_assign_str(char **cpp, const char *buf)
char ** hoc_pgargstr(int narg)
#define TRY_GUI_REDIRECT_DOUBLE(name, obj)
#define TRY_GUI_REDIRECT_DOUBLE_SEND_STRREF(name, obj)
static double inside(void *)
static philox4x32_key_t k
void hoc_continue_dialog()
void hoc_boolean_dialog()
bool var_pair_chooser(const char *, float &x, float &y, Window *w=NULL, Coord x1=400., Coord y1=400.)
bool nrn_spec_dialog_pos(Coord &x, Coord &y)
true if Style 'dialog_spec_position: on' and fills x,y with dialog_left_position and dialog_bottom_po...
bool str_chooser(const char *, char *, Window *w=NULL, Coord x=400., Coord y=400.)
bool ok_to_write(const String &, Window *w=NULL)
bool ok_to_read(const String &, Window *w=NULL)
bool boolean_dialog(const char *label, const char *accept, const char *cancel, Window *w=NULL, Coord x=400., Coord y=400.)
void continue_dialog(const char *label, Window *w=NULL, Coord x=400., Coord y=400.)