1 #include <../../nrnconf.h> 2 #if HAVE_IV // to end of file 32 #include <Dispatch/dispatcher.h> 33 #include <Dispatch/iocallback.h> 36 #include <IV-look/kit.h> 37 #include <InterViews/background.h> 38 #include <InterViews/canvas.h> 39 #include <InterViews/display.h> 40 #include <InterViews/font.h> 41 #include <InterViews/event.h> 42 #include <InterViews/hit.h> 43 #include <InterViews/layout.h> 44 #include <InterViews/printer.h> 45 #include <InterViews/selection.h> 46 #include <InterViews/style.h> 47 #include <InterViews/window.h> 48 #include <IV-2_6/InterViews/button.h> 49 #include <IV-2_6/InterViews/painter.h> 50 #include <IV-2_6/InterViews/sensor.h> 51 #include <IV-2_6/InterViews/streditor.h> 52 #include <IV-2_6/InterViews/textdisplay.h> 62 virtual ~FieldStringSEditor();
70 bool keystroke(
const Event&);
82 virtual void Reconfig();
91 void do_select(
Event&);
92 void do_grab_scroll(
Event&);
93 void do_rate_scroll(
Event&);
96 declareSelectionCallback(FieldStringSEditor)
97 implementSelectionCallback(FieldStringSEditor)
99 FieldStringSEditor::FieldStringSEditor(
107 start_ = index_ = -1;
110 FieldStringSEditor::~FieldStringSEditor() {
114 void FieldStringSEditor::Select(
int pos) {
115 start_ = index_ = pos;
116 StringEditor::Select(pos);
118 void FieldStringSEditor::Select(
int left,
int right) {
121 StringEditor::Select(left, right);
123 void FieldStringSEditor::selection(
int&
start,
int&
index) {
129 const Font* f = output->GetFont();
130 const Color* fg = output->GetFgColor();
134 FieldStringSEditor*
e = (FieldStringSEditor*)
this;
135 for (
const char*
s = e->Text(); *
s !=
'\0';
s++) {
137 p->character(f, *
s, w, fg, x, y);
142 void FieldStringSEditor::pick(
145 const Event* ep = h.event();
146 if (ep !=
NULL && h.left() < a.
right() && h.right() >= a.
left() &&
147 h.bottom() < a.
top() && h.top() >= a.
bottom()
149 h.target(depth,
this, 0);
156 switch (event.pointer_button()) {
163 start_ =
display->LineIndex(0, e.x);
189 switch (event.pointer_button()) {
198 new SelectionCallback(FieldStringSEditor)(
this, &FieldStringSEditor::cut)
205 void FieldStringSEditor::do_select(
Event& e) {
208 }
else if (e.x > xmax) {
210 xmax - width_, origin_ - (e.x - xmax)
213 display->Scroll(0, origin_, ymax);
214 index_ =
display->LineIndex(0, e.x);
215 DoSelect(start_, index_);
218 void FieldStringSEditor::do_grab_scroll(
Event& e) {
219 Window* w = canvas->window();
221 w->cursor(kit_->hand_cursor());
222 int origin =
display->Left(0, 0);
231 display->Scroll(0, origin, ymax);
234 }
while (e.middlemouse);
238 void FieldStringSEditor::do_rate_scroll(
Event& e) {
239 Window* w = canvas->window();
244 int origin =
display->Left(0, 0);
253 display->Scroll(0, origin, ymax);
260 }
while (e.rightmouse);
264 bool FieldStringSEditor::keystroke(
const Event& e) {
266 return e.mapkey(&c, 1) != 0 && HandleChar(c) && c ==
'\t';
269 void FieldStringSEditor::cursor_on() {
270 if (canvas !=
NULL) {
275 void FieldStringSEditor::cursor_off() {
276 if (canvas !=
NULL) {
281 void FieldStringSEditor::focus_in() { }
282 void FieldStringSEditor::focus_out() { }
287 s->put_value(
Text() + st, i - st);
294 void FieldStringSEditor::Reconfig() {
298 p->SetColors(kit_->foreground(), kit_->background());
299 p->SetFont(kit_->font());
302 StringEditor::Reconfig();
309 virtual ~FieldSButton();
311 virtual void Notify();
317 class FieldSEditorImpl {
322 FieldStringSEditor* editor_;
326 IOHandler* blink_handler_;
330 void blink_cursor(
long,
long);
331 void stop_blinking();
334 declareIOCallback(FieldSEditorImpl)
335 implementIOCallback(FieldSEditorImpl)
340 impl_ =
new FieldSEditorImpl;
343 impl_->build(
this, ns.string(), action);
347 FieldSEditorImpl* i =
impl_;
351 delete i->blink_handler_;
356 FieldSEditorImpl& f = *
impl_;
358 InputHandler::undraw();
362 impl_->editor_->press(e);
366 impl_->editor_->drag(e);
369 impl_->editor_->release(e);
373 FieldSEditorImpl& f = *
impl_;
374 if (f.editor_->keystroke(e)) {
381 FieldSEditorImpl& f = *
impl_;
382 f.blink_cursor(0, 0);
383 f.editor_->focus_in();
384 return InputHandler::focus_in();
388 FieldSEditorImpl& f = *
impl_;
390 f.editor_->cursor_off();
391 f.editor_->focus_out();
392 InputHandler::focus_out();
396 impl_->editor_->Message(str);
401 impl_->editor_->Message(ns.string());
405 impl_->editor_->Select(pos);
409 impl_->editor_->Select(l, r);
413 impl_->editor_->selection(start, index);
417 impl_->editor_->Edit();
421 impl_->editor_->Edit(str, left, right);
431 return &
impl_->text_;
436 void FieldSEditorImpl::build(
440 kit.begin_style(
"FieldEditor");
441 Style* s = kit.style();
442 bs_ =
new FieldSButton(e, a);
443 editor_ =
new FieldStringSEditor(bs_, str, kit_, s);
445 if (s->value_is_on(
"beveled")) {
448 LayoutKit::instance()->h_margin(editor_, 2.0),
454 cursor_is_on_ =
false;
455 blink_handler_ =
new IOCallback(FieldSEditorImpl)(
456 this, &FieldSEditorImpl::blink_cursor
459 s->find_attribute(
"cursorFlashRate", sec);
460 flash_rate_ =
long(sec * 1000000);
464 void FieldSEditorImpl::blink_cursor(
long,
long) {
466 editor_->cursor_off();
467 cursor_is_on_ =
false;
469 editor_->cursor_on();
470 cursor_is_on_ =
true;
472 if (flash_rate_ > 10) {
473 Dispatcher::instance().startTimer(0, flash_rate_, blink_handler_);
477 void FieldSEditorImpl::stop_blinking() {
478 Dispatcher::instance().stopTimer(blink_handler_);
479 editor_->cursor_off();
480 cursor_is_on_ =
false;
491 FieldSButton::~FieldSButton() {
501 void FieldSButton::Notify() {
505 if (action_ !=
NULL) {
508 action_->accept(editor_);
512 action_->cancel(editor_);
double max(double a, double b)
FieldSEditor(const String &sample, WidgetKit *, Style *, FieldSEditorAction *=NULL)
virtual void select(int pos)
virtual void press(const Event &)
virtual void field(const char *)
virtual const String * text() const
virtual void drag(const Event &)
virtual InputHandler * focus_in()
virtual void selection(int &start, int &index) const
virtual void keystroke(const Event &)
virtual void release(const Event &)
virtual void unref() const
virtual ~FieldSEditorAction()
virtual void cancel(FieldSEditor *)
#define input(prompt, fmt, var)
virtual void accept(FieldSEditor *)