NEURON
mlinedit.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 extern int hoc_return_type_code;
4 
5 #include <stdio.h>
6 
7 #if HAVE_IV
8 #include <InterViews/iv3text.h>
9 #include <InterViews/layout.h>
10 #include <InterViews/background.h>
11 #include <InterViews/event.h>
12 #include <IV-look/kit.h>
13 #include "ocglyph.h"
14 #endif
15 
16 #include "classreg.h"
17 #if HAVE_IV
18 #include "oc2iv.h"
19 #include "apwindow.h"
20 #include "ivoc.h"
21 #endif
22 
23 #include "gui-redirect.h"
24 
25 extern Object** (*nrnpy_gui_helper_)(const char* name, Object* obj);
26 extern double (*nrnpy_object_to_double_)(Object*);
27 extern char** (*nrnpy_gui_helper3_str_)(const char* name, Object* obj, int handle_strptr);
28 
29 #if HAVE_IV
30 class OcText : public Text {
31 public:
32  OcText(unsigned rows = 24, unsigned cols = 80, TextBuffer* buf = NULL);
33  virtual ~OcText();
34  virtual void keystroke(const Event& event);
35 };
36 
37 class OcMLineEditor : public OcGlyph {
38 public:
39  OcMLineEditor(unsigned row, unsigned col, const char* buf = NULL);
40  virtual ~OcMLineEditor();
41 public:
42  OcText* txt_;
43 };
44 #endif
45 
46 static double map(void* v) {
47  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("TextEditor.map", v);
48 #if HAVE_IV
49 IFGUI
50  OcMLineEditor* e = (OcMLineEditor*)v;
51  PrintableWindow* w;
52  if (ifarg(3)) {
53  w = e->make_window(float(*getarg(2)), float(*getarg(3)),
54  float(*getarg(4)), float(*getarg(5)));
55  }else{
56  w = e->make_window();
57  }
58  if (ifarg(1)) {
59  char* name = gargstr(1);
60  w->name(name);
61  }
62  w->map();
63 ENDGUI
64  return 0.;
65 #else
66  return 0.;
67 #endif
68 }
69 
70 static double readonly(void* v) {
71  TRY_GUI_REDIRECT_ACTUAL_DOUBLE("TextEditor.readonly", v);
72 #if HAVE_IV
73 IFGUI
74  OcMLineEditor* e = (OcMLineEditor*)v;
75  hoc_return_type_code = 2; // boolean
76  if (ifarg(1)) {
77  e->txt_->readOnly(int(chkarg(1, 0, 1)));
78  }
79  return double(e->txt_->readOnly());
80 ENDGUI
81 #endif
82  return 0.;
83 }
84 
85 static const char** v_text(void* v) {
86  TRY_GUI_REDIRECT_ACTUAL_STR("TextEditor.text", v);
87 #if HAVE_IV
88 IFGUI
89  OcMLineEditor* e = (OcMLineEditor*)v;
90  TextBuffer* tb = e->txt_->editBuffer();
91  if (ifarg(1)) {
92  e->txt_->reset();
93  const char* s = gargstr(1);
94  tb->Insert(0, s, strlen(s));
95  }
96  char** p = hoc_temp_charptr();
97  *p = (char*)tb->Text();
98  return (const char**)p;
99 ENDGUI
100 #endif
101  return 0;
102 }
103 
104 
105 static Member_func members[] = {
106  "readonly", readonly,
107  "map", map,
108  0,0
109 };
110 
112  "text", v_text,
113  0,0
114 };
115 
116 static void* cons(Object*) {
117  TRY_GUI_REDIRECT_OBJ("TextEditor", NULL);
118 #if HAVE_IV
119 IFGUI
120  const char* buf = "";
121  unsigned row = 5;
122  unsigned col = 30;
123  if (ifarg(1)) {
124  buf = gargstr(1);
125  }
126  if (ifarg(2)) {
127  row = unsigned(chkarg(2, 1, 1000));
128  col = unsigned(chkarg(3, 1, 1000));
129  }
130  OcMLineEditor* e = new OcMLineEditor(row, col, buf);
131  e->ref();
132  return (void*)e;
133 ENDGUI
134 #endif /* HAVE_IV */
135  return nullptr;
136 }
137 
138 static void destruct(void* v) {
139  TRY_GUI_REDIRECT_NO_RETURN("~TextEditor", v);
140 #if HAVE_IV
141 IFGUI
142  OcMLineEditor* e = (OcMLineEditor*)v;
143  if (e->has_window()) {
144  e->window()->dismiss();
145  }
146  e->unref();
147 ENDGUI
148 #endif /* HAVE_IV */
149 }
150 
152  class2oc("TextEditor", cons, destruct, members, NULL, NULL, retstr_members);
153 }
154 
155 #if HAVE_IV
156 OcMLineEditor::OcMLineEditor(unsigned row, unsigned col, const char* buf) {
157  txt_ = new OcText(row, col, new TextBuffer(buf,strlen(buf),1000));
158  txt_->ref();
159  body(
160  new Background(
161  txt_,
162  WidgetKit::instance()->background()
163  )
164  );
165 }
166 OcMLineEditor::~OcMLineEditor() {
167  txt_->unref();
168 }
169 
170 OcText::OcText(unsigned rows, unsigned cols, TextBuffer* buf) :
171  Text(rows, cols, buf)
172 {
173 }
174 
175 OcText::~OcText() {}
176 
177 void OcText::keystroke(const Event& e){
178  if (readOnly_) {
179  return;
180  }
181  char buffer[8]; // needs to be dynamically adjusted
182  int count = e.mapkey(buffer, 8);
183  if (count <= 0) {
184  return;
185  }
186  Text::keystroke(e);
187 }
188 
189 #endif
void TextEditor_reg()
Definition: mlinedit.cpp:151
#define TRY_GUI_REDIRECT_NO_RETURN(name, obj)
Definition: gui-redirect.h:44
#define TRY_GUI_REDIRECT_ACTUAL_STR(name, obj)
Definition: gui-redirect.h:76
size_t p
static double readonly(void *v)
Definition: mlinedit.cpp:70
static const char ** v_text(void *v)
Definition: mlinedit.cpp:85
#define v
Definition: md1redef.h:4
int hoc_return_type_code
Definition: code.cpp:41
#define TRY_GUI_REDIRECT_ACTUAL_DOUBLE(name, obj)
Definition: gui-redirect.h:66
virtual const char * name() const
static Member_func members[]
Definition: mlinedit.cpp:105
#define e
Definition: passive0.cpp:24
#define gargstr
Definition: hocdec.h:14
#define Text
Definition: _defines.h:297
static double map(void *v)
Definition: mlinedit.cpp:46
virtual void map()
_CONST char * s
Definition: system.cpp:74
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
Definition: hoc_oop.cpp:1581
#define ENDGUI
Definition: hocdec.h:352
static Member_ret_str_func retstr_members[]
Definition: mlinedit.cpp:111
char * name
Definition: init.cpp:16
static void destruct(void *v)
Definition: mlinedit.cpp:138
#define Event
Definition: _defines.h:107
int ifarg(int)
Definition: code.cpp:1562
static unsigned row
Definition: nonlin.cpp:89
#define TRY_GUI_REDIRECT_OBJ(name, obj)
Definition: gui-redirect.h:12
Definition: hocdec.h:226
#define getarg
Definition: hocdec.h:15
char buf[512]
Definition: init.cpp:13
static void * cons(Object *)
Definition: mlinedit.cpp:116
#define Background
Definition: _defines.h:43
#define IFGUI
Definition: hocdec.h:351
char ** hoc_temp_charptr(void)
Definition: code.cpp:625
double(* nrnpy_object_to_double_)(Object *)
Definition: xmenu.cpp:14
return NULL
Definition: cabcode.cpp:461
double chkarg(int, double low, double high)
Definition: code2.cpp:608
#define TextBuffer
Definition: _defines.h:299