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>
19 #include <OS/string.h>
27 Style*
s = Session::instance()->style();
28 if (
s->value_is_on(
"dialog_spec_position")) {
29 s->find_attribute(
"dialog_left_position", x);
30 s->find_attribute(
"dialog_bottom_position", y);
38 return d->post_at_aligned(x, y, 0.0, 0.0);
40 if (x != 400. || y != 400.) {
41 return d->post_at_aligned(x, y, .5, .5);
43 Display* dis = Session::instance()->default_display();
44 return d->post_at_aligned(dis->width() / 2, dis->height() / 2, .5, .5);
55 class OcGlyphDialog:
public Dialog {
58 virtual ~OcGlyphDialog();
62 class DialogAction:
public Action {
64 DialogAction(
Dialog*,
bool);
65 virtual ~DialogAction();
66 virtual void execute() {
74 DialogAction::DialogAction(
Dialog* d,
bool accept) {
78 DialogAction::~DialogAction() {
92 Dialog* d =
new Dialog(
k.outset_frame(l.margin(vbox, 5)), Session::instance()->style());
94 vbox->append(l.hcenter(
k.inset_frame(l.margin(
k.label(label), 10))));
95 vbox->append(l.hcenter(l.hbox(
k.push_button(accept,
new DialogAction(d,
true)),
97 k.push_button(cancel,
new DialogAction(d,
false)))));
101 ok = oc_post_dialog(d, x, y);
111 Dialog* d =
new Dialog(
k.outset_frame(l.margin(vbox, 5)), Session::instance()->style());
113 vbox->append(l.hcenter(
k.inset_frame(l.margin(
k.label(label), 10))));
114 vbox->append(l.hcenter(
k.push_button(
"Continue",
new DialogAction(d,
true))));
118 oc_post_dialog(d, x, y);
123 static bool ok_if_already_exists(
const char*
s,
Window* w) {
129 static void open_fail(
const char*
s,
Window* w,
const char* io) {
137 if (obuf.open(
s, std::ios::in)) {
139 if (!ok_if_already_exists(
s, w)) {
144 if (obuf.open(
s, std::ios::app | std::ios::out)) {
147 open_fail(
s, w,
"writ");
157 if (obuf.open(
s, std::ios::in)) {
162 open_fail(
s, w,
"read");
170 float x1 = x, y1 = y;
174 if (sscanf(
buf,
"%f%f", &x1, &y1) == 2) {
179 continue_dialog(
"Invalid entry: Enter pair of numbers separated by space.", w);
191 style->attribute(
"caption", caption);
198 ok = oc_post_dialog(d, x, y);
201 strcpy(
buf, d->
text()->string());
218 fe_->select(0,
fe_->text()->length());
219 return Dialog::run();
232 WidgetKit& widgets = *WidgetKit::instance();
233 DialogKit& dialogs = *DialogKit::instance();
234 LayoutKit& layout = *LayoutKit::instance();
239 style->find_attribute(
"caption", caption);
240 style->find_attribute(
"accept",
accept);
241 style->find_attribute(
"cancel",
cancel);
244 g = widgets.inset_frame(layout.margin(layout.flexible(vb,
fil, 0), 10.0));
254 fd->
s_ = *fe->text();
256 vb->append(layout.flexible(widgets.label(caption)));
257 vb->append(layout.vglue(10));
260 vb->append(layout.vglue(10));
263 vb->append(layout.vglue(10));
266 hb->append(layout.hglue(20,
fil, 20));
267 hb->append(widgets.default_button(
accept,
new DialogAction(fd,
true)));
268 hb->append(layout.hglue(5));
269 hb->append(widgets.push_button(
cancel,
new DialogAction(fd,
false)));
270 hb->append(layout.hglue(20,
fil, 20));
324 class LabelChooserAction:
public Action {
326 LabelChooserAction(
GLabel*);
327 virtual ~LabelChooserAction();
329 virtual void execute();
340 style->attribute(
"caption", caption);
342 LabelChooserAction* lca =
new LabelChooserAction(gl);
343 Button* b =
k.check_box(
"vfixed", lca);
344 lca->state(b->state());
349 ok = oc_post_dialog(d, x, y);
351 strcpy(
buf, d->
text()->string());
357 LabelChooserAction::LabelChooserAction(
GLabel* gl) {
362 LabelChooserAction::~LabelChooserAction() {
370 ts_->set(TelltaleState::is_chosen,
false);
372 ts_->set(TelltaleState::is_chosen,
true);
376 void LabelChooserAction::execute() {
377 if (ts_->test(TelltaleState::is_chosen)) {
379 gl_->vfixed(gl_->scale());
383 gl_->fixed(gl_->scale());
396 bool OcGlyph::dialog(
const char* label,
const char* accept,
const char* cancel) {
401 d_ =
new OcGlyphDialog(
k.outset_frame(l.margin(vbox, 5)), Session::instance()->style());
403 vbox->append(l.hcenter(l.hflexible(l.margin(
k.label(label), 10),
fil, 0)));
404 vbox->append(l.hcenter(
this));
405 vbox->append(l.hcenter(l.hflexible(l.hbox(
k.push_button(accept,
new DialogAction(
d_,
true)),
407 k.push_button(cancel,
new DialogAction(
d_,
false))),
411 ok = oc_post_dialog(
d_, 400., 400.);
420 OcGlyphDialog::~OcGlyphDialog() {}
422 const Event* e = h.event();
427 body()->pick(
c, a, depth + 1, h);
431 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
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 *)
impl_ptrs methods
Collection of pointers to functions with python-version-specific implementations.
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
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.)