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();
110 const char* pattern_attribute,
const char* default_pattern,
111 const char* caption_attribute,
const char* default_caption,
115 void accept_browser();
116 void accept_browser_index(
int);
117 void cancel_browser();
120 bool chdir(
int,
int);
123 class SymBrowserAccept :
public Action {
125 SymBrowserAccept(SymChooserImpl*,
int);
126 virtual ~SymBrowserAccept();
129 SymChooserImpl* sci_;
133 SymBrowserAccept::SymBrowserAccept(SymChooserImpl* sci,
int browser_index) {
135 browser_index_ = browser_index;
138 SymBrowserAccept::~SymBrowserAccept(){}
141 sci_->accept_browser_index(browser_index_);
150 const char* caption =
"Choose a Variable Name or";
154 Style* style =
new Style(Session::instance()->style());
155 style->attribute(
"caption", caption);
186 Display* d = Session::instance()->default_display();
189 b = sc->post_at_aligned(x, y, 0.0, 0.0);
191 b = sc->post_at_aligned(d->width()/2, d->height()/2, .5, .5);
221 declareActionCallback(SymChooserImpl)
222 implementActionCallback(SymChooserImpl)
224 declareFieldEditorCallback(SymChooserImpl)
225 implementFieldEditorCallback(SymChooserImpl)
227 #define SHOW_SECTION 1 233 impl_ =
new SymChooserImpl(nbrowser);
234 SymChooserImpl& fc = *impl_;
256 return impl_->selected_;
260 return impl_->selected_var();
264 return impl_->selected_vector_count();
268 SymChooserImpl& fc = *impl_;
270 if (!fc.chdir(fc.dir_->path())) {
277 Dialog::dismiss(accept);
278 SymChooserImpl& fc = *impl_;
279 if (fc.action_ !=
NULL) {
280 fc.action_->execute(
this, accept);
285 SymChooserImpl::SymChooserImpl(
int nbrowser) {
286 nbrowser_ = nbrowser;
290 for (
int i=0;
i < nbrowser_; ++
i) {
295 SymChooserImpl::~SymChooserImpl() {
307 style_ =
new Style(s);
309 style_->alias(
"FileChooser");
310 style_->alias(
"Dialog");
311 update_ =
new ActionCallback(SymChooserImpl)(
312 this, &SymChooserImpl::build
314 style_->add_trigger_any(update_);
318 void SymChooserImpl::scfree() {
320 for (
int i=nbrowser_-1;
i >= 0; --
i) {
323 delete [] filter_map_;
325 style_->remove_trigger_any(update_);
329 void SymChooserImpl::build() {
331 const LayoutKit& layout = *LayoutKit::instance();
336 s->find_attribute(
"caption", caption);
337 String subcaption(
"Enter Symbol name:");
338 s->find_attribute(
"subcaption", subcaption);
340 s->find_attribute(
"open", open);
342 s->find_attribute(
"cancel", close);
344 s->find_attribute(
"rows", rows);
345 const Font* f = kit.font();
348 Coord height = rows * (bbox.ascent() + bbox.descent()) + 1.0;
350 if (!s->find_attribute(
"width", width)) {
351 width = 16 * f->width(
'm') + 3.0;
355 Action* accept =
new ActionCallback(SymChooserImpl)(
356 this, &SymChooserImpl::accept_browser
358 Action* cancel =
new ActionCallback(SymChooserImpl)(
359 this, &SymChooserImpl::cancel_browser
361 editor_ = DialogKit::instance()->field_editor(
363 new FieldEditorCallback(SymChooserImpl)(
364 this, &SymChooserImpl::editor_accept,
NULL 368 for (i=0; i < nbrowser_; ++
i) {
370 new SymBrowserAccept(
this, i),
373 fchooser_->remove_all_input_handlers();
374 fchooser_->append_input_handler(editor_);
375 for (i=0; i < nbrowser_; ++
i) {
376 fchooser_->append_input_handler(fbrowser_[i]);
378 fchooser_->next_focus();
381 if (caption.
length() > 0) {
382 g->append(layout.r_margin(kit.fancy_label(caption), 5.0,
fil, 0.0));
384 if (subcaption.
length() > 0) {
385 g->append(layout.r_margin(kit.fancy_label(subcaption), 5.0,
fil, 0.0));
387 g->append(layout.vglue(5.0, 0.0, 2.0));
389 g->append(layout.vglue(5.0, 0.0, 2.0));
390 g->append(makeshowmenu());
391 g->append(layout.vglue(15.0, 0.0, 12.0));
394 for (i=0; i < nbrowser_; ++
i) {
399 layout.natural_span(fbrowser_[i], width, height), 1.0
405 kit.vscroll_bar(fbrowser_[i]->adjustable())
410 g->append(layout.vspace(15.0));
411 if (s->value_is_on(
"filter")) {
413 this, &SymChooserImpl::filter_accept,
NULL 415 filter_ = add_filter(
416 s,
"filterPattern",
"",
"filterCaption",
"Filter:", g, action
418 if (s->value_is_on(
"directoryFilter")) {
419 directory_filter_ = add_filter(
420 s,
"directoryFilterPattern",
"",
421 "directoryFilterCaption",
"Name Filter:", g, action
424 directory_filter_ =
NULL;
428 directory_filter_ =
NULL;
433 layout.vcenter(kit.default_button(open, accept)),
434 layout.hglue(10.0, 0.0, 5.0),
435 layout.vcenter(kit.push_button(close, cancel)),
441 layout.vcenter(kit.outset_frame(layout.margin(g, 5.0)), 1.0)
447 Menu* SymChooserImpl::makeshowmenu() {
449 Menu* mb = k.menubar();
450 MenuItem* mi = k.menubar_item(
"Show");
452 Menu* mp = k.pulldown();
457 mi->action(
new ActionCallback(SymChooserImpl)(
458 this, &SymChooserImpl::show_all
461 mi->state()->set(TelltaleState::is_chosen,
true);
464 mi->action(
new ActionCallback(SymChooserImpl)(
465 this, &SymChooserImpl::show_var
470 mi->action(
new ActionCallback(SymChooserImpl)(
471 this, &SymChooserImpl::show_objref
476 mi->action(
new ActionCallback(SymChooserImpl)(
477 this, &SymChooserImpl::show_objid
482 mi->action(
new ActionCallback(SymChooserImpl)(
483 this, &SymChooserImpl::show_sec
487 mi->state()->set(TelltaleState::is_chosen,
true);
490 mi->action(
new ActionCallback(SymChooserImpl)(
491 this, &SymChooserImpl::show_pysec
498 void SymChooserImpl::show(
int i) {
505 void SymChooserImpl::show_all() {
508 void SymChooserImpl::show_var() {
511 void SymChooserImpl::show_objref() {
514 void SymChooserImpl::show_objid() {
517 void SymChooserImpl::show_sec() {
520 void SymChooserImpl::show_pysec() {
524 void SymChooserImpl::clear(
int bindex) {
525 for (
int bi = bindex ; bi < nbrowser_; ++bi) {
531 b.remove_selectable(0);
541 void SymChooserImpl::load(
int bindex) {
543 Browser& b = *fbrowser_[bindex];
547 const LayoutKit& layout = *LayoutKit::instance();
548 int dircount = d.
count();
549 delete [] filter_map_;
550 int*
index =
new int[dircount];
553 for (
int i = 0; i < dircount; i++) {
556 if ((is_dir && filtered(f, directory_filter_)) ||
557 (!is_dir && filtered(f, filter_))
562 name = layout.hbox(name, kit.label(
"_"));
564 name = layout.hbox(name, kit.label(
"."));
568 layout.h_margin(name, 3.0, 0.0, 0.0, 15.0,
fil, 0.0),
572 b.append_selectable(t);
573 b.append(
new ChoiceItem(t, label, kit.bright_inset_frame(label)));
580 fbrowser_[bindex]->refresh();
581 editor_->field(d.
path());
587 const char* pattern_attribute,
const char* default_pattern,
588 const char* caption_attribute,
const char* default_caption,
592 s->find_attribute(pattern_attribute, pattern);
593 String caption(default_caption);
594 s->find_attribute(caption_attribute, caption);
595 FieldEditor*
e = DialogKit::instance()->field_editor(pattern, s, action);
596 fchooser_->append_input_handler(e);
598 LayoutKit& layout = *LayoutKit::instance();
601 layout.vcenter(kit.fancy_label(caption), 0.5),
603 layout.vcenter(e, 0.5)
606 body->append(layout.vspace(10.0));
614 const String* s = e->text();
621 void SymChooserImpl::accept_browser_index(
int bindex) {
622 int i =
int(fbrowser_[bindex]->selected());
632 char* tmp =
new char[length + 2];
638 last_selected_ = tmp;
640 selected_ = editor_->text();
642 if (chdir(bindex, i)) {
643 fchooser_->focus(editor_);
649 browser_index_ = bindex;
655 double* SymChooserImpl::selected_var() {
656 if (last_index_ != -1
657 && strcmp(selected_->string(), last_selected_.string()) == 0) {
665 int SymChooserImpl::selected_vector_count() {
666 if (last_index_ != -1
667 && strcmp(selected_->string(), last_selected_.string()) == 0) {
675 void SymChooserImpl::accept_browser() {
676 int bi = browser_index_;
677 int i =
int(fbrowser_[bi]->selected());
679 editor_accept(editor_);
683 const String& path = dir_[bi]->path();
684 const String& name = dir_[bi]->name(i);
686 char* tmp =
new char[length + 1];
693 selected_ = editor_->text();
694 if (dir_[bi]->is_directory(i)) {
696 fchooser_->focus(editor_);
701 fchooser_->dismiss(
true);
706 void SymChooserImpl::cancel_browser() {
708 fchooser_->dismiss(
false);
711 void SymChooserImpl::editor_accept(
FieldEditor* e) {
713 int bi = browser_index_;
714 if ((i = dir_[bi]->
index(*e->text())) >= 0 ) {
716 selected_ = &dir_[bi]->name(i);
717 fchooser_->dismiss(
true);
721 selected_ = e->text();
722 fchooser_->dismiss(
true);
731 bool SymChooserImpl::chdir(
int bindex,
int index) {
732 if (dir_[bindex]->is_directory(index)) {
735 if (dir_[bindex]->obj(index)) {
738 }
else if (dir_[bindex]->
is_pysec(index)) {
743 dir_[bindex]->path(),
744 dir_[bindex]->
object(),
745 dir_[bindex]->symbol(index),
746 dir_[bindex]->array_index(index));
749 if (bi > nbrowser_-1) {
SymDirectory * newsymdir(int index)
#define TRY_GUI_REDIRECT_NO_RETURN(name, obj)
static void * scons(Object *)
static void sdestruct(void *v)
virtual const String & name(int index) const
Symbol * hoc_lookup(const char *)
virtual int whole_vector(int index)
virtual int selected_vector_count()
virtual void dismiss(bool)
static MenuItem * radio_menu_item(TelltaleGroup *, const char *)
static bool match(const String &name, const String &pattern)
char ** hoc_pgargstr(int narg)
double(* nrnpy_object_to_double_)(Object *)
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)
#define TRY_GUI_REDIRECT_ACTUAL_DOUBLE(name, obj)
virtual int count() const
const char * string() const
void hoc_assign_str(char **cpp, const char *buf)
int const size_t const size_t n
Symbol * symbol(int index) const
virtual double * variable(int index)
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...
virtual double * selected_var()
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
virtual ~SymChooserAction()
virtual void execute(SymChooser *, bool accept)
virtual void unref() const
#define FieldEditorAction
virtual const String & path() const
#define TRY_GUI_REDIRECT_OBJ(name, obj)
static Member_func members[]
virtual bool is_directory(int index) const
static double srun(void *v)
virtual const String * selected() const
SymChooser(SymDirectory *, WidgetKit *, Style *, SymChooserAction *=NULL, int nbrowser=3)
static double text(void *v)
static PyObject * is_pysec(NPySecObj *self)