1 #include <../../nrnconf.h>
34 #include <IV-look/choice.h>
35 #include <IV-look/dialogs.h>
36 #include <IV-look/fbrowser.h>
37 #include <IV-look/kit.h>
38 #include <InterViews/action.h>
39 #include <InterViews/event.h>
40 #include <InterViews/font.h>
41 #include <InterViews/hit.h>
42 #include <InterViews/input.h>
43 #include <InterViews/layout.h>
44 #include <InterViews/scrbox.h>
45 #include <InterViews/style.h>
46 #include <InterViews/target.h>
47 #include <InterViews/session.h>
48 #include <InterViews/display.h>
68 class SymChooserImpl {
71 friend class SymBrowserAccept;
72 SymChooserImpl(
int nbrowser);
106 double* selected_var();
107 int selected_vector_count();
109 const char* pattern_attribute,
110 const char* default_pattern,
111 const char* caption_attribute,
112 const char* default_caption,
116 void accept_browser();
117 void accept_browser_index(
int);
118 void cancel_browser();
121 bool chdir(
int,
int);
124 class SymBrowserAccept:
public Action {
126 SymBrowserAccept(SymChooserImpl*,
int);
127 virtual ~SymBrowserAccept();
131 SymChooserImpl* sci_;
135 SymBrowserAccept::SymBrowserAccept(SymChooserImpl* sci,
int browser_index) {
137 browser_index_ = browser_index;
140 SymBrowserAccept::~SymBrowserAccept() {}
143 sci_->accept_browser_index(browser_index_);
152 const char* caption =
"Choose a Variable Name or";
156 Style* style =
new Style(Session::instance()->style());
157 style->attribute(
"caption", caption);
188 Display* d = Session::instance()->default_display();
191 b = sc->post_at_aligned(x, y, 0.0, 0.0);
193 b = sc->post_at_aligned(d->width() / 2, d->height() / 2, .5, .5);
219 declareActionCallback(SymChooserImpl) implementActionCallback(SymChooserImpl)
221 declareFieldEditorCallback(SymChooserImpl) implementFieldEditorCallback(SymChooserImpl)
222 #define SHOW_SECTION 1
230 impl_ =
new SymChooserImpl(nbrowser);
231 SymChooserImpl& fc = *impl_;
253 return impl_->selected_;
257 return impl_->selected_var();
261 return impl_->selected_vector_count();
265 SymChooserImpl& fc = *
impl_;
267 if (!fc.chdir(fc.dir_->path())) {
274 Dialog::dismiss(accept);
275 SymChooserImpl& fc = *
impl_;
276 if (fc.action_ !=
NULL) {
277 fc.action_->execute(
this, accept);
282 SymChooserImpl::SymChooserImpl(
int nbrowser) {
283 nbrowser_ = nbrowser;
287 for (
int i = 0;
i < nbrowser_; ++
i) {
292 SymChooserImpl::~SymChooserImpl() {
302 style_ =
new Style(s);
304 style_->alias(
"FileChooser");
305 style_->alias(
"Dialog");
306 update_ =
new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::build);
307 style_->add_trigger_any(update_);
311 void SymChooserImpl::scfree() {
313 for (
int i = nbrowser_ - 1;
i >= 0; --
i) {
316 delete[] filter_map_;
318 style_->remove_trigger_any(update_);
322 void SymChooserImpl::build() {
324 const LayoutKit& layout = *LayoutKit::instance();
329 s->find_attribute(
"caption", caption);
330 String subcaption(
"Enter Symbol name:");
331 s->find_attribute(
"subcaption", subcaption);
333 s->find_attribute(
"open", open);
335 s->find_attribute(
"cancel", close);
337 s->find_attribute(
"rows", rows);
338 const Font* f = kit.font();
341 Coord height = rows * (bbox.ascent() + bbox.descent()) + 1.0;
343 if (!s->find_attribute(
"width", width)) {
344 width = 16 * f->width(
'm') + 3.0;
348 Action* accept =
new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::accept_browser);
349 Action* cancel =
new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::cancel_browser);
350 editor_ = DialogKit::instance()->field_editor(
351 "", s,
new FieldEditorCallback(SymChooserImpl)(
this, &SymChooserImpl::editor_accept,
NULL));
353 for (
i = 0;
i < nbrowser_; ++
i) {
356 fchooser_->remove_all_input_handlers();
357 fchooser_->append_input_handler(editor_);
358 for (
i = 0;
i < nbrowser_; ++
i) {
359 fchooser_->append_input_handler(fbrowser_[
i]);
361 fchooser_->next_focus();
364 if (caption.length() > 0) {
365 g->append(layout.r_margin(kit.fancy_label(caption), 5.0,
fil, 0.0));
367 if (subcaption.length() > 0) {
368 g->append(layout.r_margin(kit.fancy_label(subcaption), 5.0,
fil, 0.0));
370 g->append(layout.vglue(5.0, 0.0, 2.0));
372 g->append(layout.vglue(5.0, 0.0, 2.0));
373 g->append(makeshowmenu());
374 g->append(layout.vglue(15.0, 0.0, 12.0));
377 for (
i = 0;
i < nbrowser_; ++
i) {
378 b = layout.hbox(layout.vcenter(kit.inset_frame(layout.margin(
379 layout.natural_span(fbrowser_[
i], width, height), 1.0)),
382 kit.vscroll_bar(fbrowser_[
i]->adjustable()));
386 g->append(layout.vspace(15.0));
387 if (s->value_is_on(
"filter")) {
389 SymChooserImpl)(
this, &SymChooserImpl::filter_accept,
NULL);
390 filter_ = add_filter(s,
"filterPattern",
"",
"filterCaption",
"Filter:",
g, action);
391 if (s->value_is_on(
"directoryFilter")) {
392 directory_filter_ = add_filter(s,
393 "directoryFilterPattern",
395 "directoryFilterCaption",
400 directory_filter_ =
NULL;
404 directory_filter_ =
NULL;
406 g->append(layout.hbox(layout.hglue(10.0),
407 layout.vcenter(kit.default_button(open, accept)),
408 layout.hglue(10.0, 0.0, 5.0),
409 layout.vcenter(kit.push_button(close, cancel)),
410 layout.hglue(10.0)));
412 fchooser_->body(layout.vcenter(kit.outset_frame(layout.margin(
g, 5.0)), 1.0));
417 Menu* SymChooserImpl::makeshowmenu() {
419 Menu* mb =
k.menubar();
422 Menu* mp =
k.pulldown();
427 mi->action(
new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_all));
429 mi->state()->set(TelltaleState::is_chosen,
true);
432 mi->action(
new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_var));
436 mi->action(
new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_objref));
440 mi->action(
new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_objid));
444 mi->action(
new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_sec));
447 mi->state()->set(TelltaleState::is_chosen,
true);
450 mi->action(
new ActionCallback(SymChooserImpl)(
this, &SymChooserImpl::show_pysec));
456 void SymChooserImpl::show(
int i) {
463 void SymChooserImpl::show_all() {
466 void SymChooserImpl::show_var() {
469 void SymChooserImpl::show_objref() {
472 void SymChooserImpl::show_objid() {
475 void SymChooserImpl::show_sec() {
478 void SymChooserImpl::show_pysec() {
482 void SymChooserImpl::clear(
int bindex) {
483 for (
int bi = bindex; bi < nbrowser_; ++bi) {
489 b.remove_selectable(0);
499 void SymChooserImpl::load(
int bindex) {
501 Browser& b = *fbrowser_[bindex];
505 const LayoutKit& layout = *LayoutKit::instance();
506 int dircount = d.
count();
507 delete[] filter_map_;
508 int*
index =
new int[dircount];
511 for (
int i = 0;
i < dircount;
i++) {
514 if ((is_dir && filtered(f, directory_filter_)) || (!is_dir && filtered(f, filter_))) {
518 name = layout.hbox(
name, kit.label(
"_"));
520 name = layout.hbox(
name, kit.label(
"."));
526 b.append_selectable(
t);
527 b.append(
new ChoiceItem(
t, label, kit.bright_inset_frame(label)));
534 fbrowser_[bindex]->refresh();
535 editor_->field(d.
path());
540 const char* pattern_attribute,
541 const char* default_pattern,
542 const char* caption_attribute,
543 const char* default_caption,
547 s->find_attribute(pattern_attribute,
pattern);
548 String caption(default_caption);
549 s->find_attribute(caption_attribute, caption);
551 fchooser_->append_input_handler(
e);
553 LayoutKit& layout = *LayoutKit::instance();
554 body->append(layout.hbox(layout.vcenter(kit.fancy_label(caption), 0.5),
556 layout.vcenter(
e, 0.5)));
557 body->append(layout.vspace(10.0));
572 void SymChooserImpl::accept_browser_index(
int bindex) {
573 int i = int(fbrowser_[bindex]->selected());
583 char* tmp =
new char[length + 2];
586 last_selected_ = tmp;
588 selected_ = editor_->text();
590 if (chdir(bindex,
i)) {
591 fchooser_->focus(editor_);
597 browser_index_ = bindex;
603 double* SymChooserImpl::selected_var() {
604 if (last_index_ != -1 && strcmp(selected_->string(), last_selected_.string()) == 0) {
612 int SymChooserImpl::selected_vector_count() {
613 if (last_index_ != -1 && strcmp(selected_->string(), last_selected_.string()) == 0) {
621 void SymChooserImpl::accept_browser() {
622 int bi = browser_index_;
623 int i = int(fbrowser_[bi]->selected());
625 editor_accept(editor_);
629 const String& path = dir_[bi]->path();
632 char* tmp =
new char[length + 1];
636 selected_ = editor_->text();
637 if (dir_[bi]->is_directory(
i)) {
639 fchooser_->focus(editor_);
644 fchooser_->dismiss(
true);
649 void SymChooserImpl::cancel_browser() {
651 fchooser_->dismiss(
false);
656 int bi = browser_index_;
657 if ((
i = dir_[bi]->
index(*
e->text())) >= 0) {
659 selected_ = &dir_[bi]->name(
i);
660 fchooser_->dismiss(
true);
664 selected_ =
e->text();
665 fchooser_->dismiss(
true);
674 bool SymChooserImpl::chdir(
int bindex,
int index) {
675 if (dir_[bindex]->is_directory(
index)) {
678 if (dir_[bindex]->obj(
index)) {
686 dir_[bindex]->
object(),
687 dir_[bindex]->symbol(
index),
688 dir_[bindex]->array_index(
index));
691 if (bi > nbrowser_ - 1) {
#define FieldEditorAction
static MenuItem * radio_menu_item(TelltaleGroup *, const char *)
virtual void unref() const
const char * string() const
virtual void execute(SymChooser *, bool accept)
virtual ~SymChooserAction()
virtual void dismiss(bool)
virtual double * selected_var()
virtual const String * selected() const
virtual int selected_vector_count()
SymChooser(SymDirectory *, WidgetKit *, Style *, SymChooserAction *=NULL, int nbrowser=3)
virtual const String & path() const
virtual int count() const
virtual double * variable(int index)
static bool match(const String &name, const String &pattern)
virtual int whole_vector(int index)
Symbol * symbol(int index) const
SymDirectory * newsymdir(int index)
virtual const String & name(int index) const
virtual bool is_directory(int index) 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)
void hoc_assign_str(char **cpp, const char *buf)
Symbol * hoc_lookup(const char *)
char ** hoc_pgargstr(int narg)
#define TRY_GUI_REDIRECT_ACTUAL_DOUBLE(name, obj)
#define TRY_GUI_REDIRECT_NO_RETURN(name, obj)
#define TRY_GUI_REDIRECT_OBJ(name, obj)
int const size_t const size_t n
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
static PyObject * is_pysec(NPySecObj *self)
static philox4x32_key_t k
static double text(void *v)
static Member_func members[]
double(* nrnpy_object_to_double_)(Object *)
static double srun(void *v)
static void * scons(Object *)
static void sdestruct(void *v)
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...