1 #include <../../nrnconf.h>
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>
60 virtual ~FieldStringSEditor();
68 bool keystroke(
const Event&);
81 virtual void Reconfig();
91 void do_select(
Event&);
92 void do_grab_scroll(
Event&);
93 void do_rate_scroll(
Event&);
96 declareSelectionCallback(FieldStringSEditor) implementSelectionCallback(FieldStringSEditor)
98 FieldStringSEditor::FieldStringSEditor(
ButtonState* bs,
108 start_ = index_ = -1;
111 FieldStringSEditor::~FieldStringSEditor() {
115 void FieldStringSEditor::Select(
int pos) {
116 start_ = index_ = pos;
117 StringEditor::Select(pos);
119 void FieldStringSEditor::Select(
int left,
int right) {
124 void FieldStringSEditor::selection(
int&
start,
int&
index) {
130 const Font* f = output->GetFont();
131 const Color* fg = output->GetFgColor();
135 FieldStringSEditor*
e = (FieldStringSEditor*)
this;
136 for (
const char* s =
e->Text(); *s !=
'\0'; s++) {
137 Coord w = f->width(*s);
138 p->character(f, *s, w, fg, x, y);
144 const Event* ep = h.event();
145 if (ep !=
NULL && h.left() < a.
right() && h.right() >= a.
left() && h.bottom() < a.
top() &&
147 h.target(depth,
this, 0);
154 switch (event.pointer_button()) {
161 start_ =
display->LineIndex(0,
e.x);
185 switch (event.pointer_button()) {
192 s->own(
new SelectionCallback(FieldStringSEditor)(
this, &FieldStringSEditor::cut));
197 void FieldStringSEditor::do_select(
Event&
e) {
200 }
else if (
e.x > xmax) {
201 origin_ =
Math::max(xmax - width_, origin_ - (
e.x - xmax));
203 display->Scroll(0, origin_, ymax);
204 index_ =
display->LineIndex(0,
e.x);
205 DoSelect(start_, index_);
208 void FieldStringSEditor::do_grab_scroll(
Event&
e) {
209 Window* w = canvas->window();
211 w->cursor(kit_->hand_cursor());
212 int origin =
display->Left(0, 0);
219 display->Scroll(0, origin, ymax);
222 }
while (
e.middlemouse);
226 void FieldStringSEditor::do_rate_scroll(
Event&
e) {
227 Window* w = canvas->window();
232 int origin =
display->Left(0, 0);
239 display->Scroll(0, origin, ymax);
246 }
while (
e.rightmouse);
250 bool FieldStringSEditor::keystroke(
const Event&
e) {
252 return e.mapkey(&
c, 1) != 0 && HandleChar(
c) &&
c ==
'\t';
255 void FieldStringSEditor::cursor_on() {
256 if (canvas !=
NULL) {
261 void FieldStringSEditor::cursor_off() {
262 if (canvas !=
NULL) {
267 void FieldStringSEditor::focus_in() {}
268 void FieldStringSEditor::focus_out() {}
274 s->put_value(
Text() + st,
i - st);
281 void FieldStringSEditor::Reconfig() {
285 p->SetColors(kit_->foreground(), kit_->background());
286 p->SetFont(kit_->font());
289 StringEditor::Reconfig();
296 virtual ~FieldSButton();
298 virtual void Notify();
305 class FieldSEditorImpl {
310 FieldStringSEditor* editor_;
314 IOHandler* blink_handler_;
318 void blink_cursor(
long,
long);
319 void stop_blinking();
322 declareIOCallback(FieldSEditorImpl) implementIOCallback(FieldSEditorImpl)
329 impl_ =
new FieldSEditorImpl;
332 impl_->build(
this, ns.string(), action);
336 FieldSEditorImpl*
i =
impl_;
340 delete i->blink_handler_;
345 FieldSEditorImpl& f = *
impl_;
347 InputHandler::undraw();
358 impl_->editor_->release(
e);
362 FieldSEditorImpl& f = *
impl_;
363 if (f.editor_->keystroke(
e)) {
370 FieldSEditorImpl& f = *
impl_;
371 f.blink_cursor(0, 0);
372 f.editor_->focus_in();
373 return InputHandler::focus_in();
377 FieldSEditorImpl& f = *
impl_;
379 f.editor_->cursor_off();
380 f.editor_->focus_out();
381 InputHandler::focus_out();
385 impl_->editor_->Message(str);
390 impl_->editor_->Message(ns.string());
394 impl_->editor_->Select(pos);
398 impl_->editor_->Select(l, r);
406 impl_->editor_->Edit();
420 return &
impl_->text_;
427 kit.begin_style(
"FieldEditor");
428 Style* s = kit.style();
429 bs_ =
new FieldSButton(
e, a);
430 editor_ =
new FieldStringSEditor(bs_, str, kit_, s);
432 if (s->value_is_on(
"beveled")) {
434 new Background(LayoutKit::instance()->h_margin(editor_, 2.0), kit.background()));
437 cursor_is_on_ =
false;
438 blink_handler_ =
new IOCallback(FieldSEditorImpl)(
this, &FieldSEditorImpl::blink_cursor);
440 s->find_attribute(
"cursorFlashRate",
sec);
441 flash_rate_ = long(
sec * 1000000);
445 void FieldSEditorImpl::blink_cursor(
long,
long) {
447 editor_->cursor_off();
448 cursor_is_on_ =
false;
450 editor_->cursor_on();
451 cursor_is_on_ =
true;
453 if (flash_rate_ > 10) {
454 Dispatcher::instance().startTimer(0, flash_rate_, blink_handler_);
458 void FieldSEditorImpl::stop_blinking() {
459 Dispatcher::instance().stopTimer(blink_handler_);
460 editor_->cursor_off();
461 cursor_is_on_ =
false;
472 FieldSButton::~FieldSButton() {
482 void FieldSButton::Notify() {
486 if (action_ !=
NULL) {
489 action_->accept(editor_);
493 action_->cancel(editor_);
virtual void cancel(FieldSEditor *)
virtual ~FieldSEditorAction()
virtual void accept(FieldSEditor *)
virtual void release(const Event &)
virtual const String * text() const
virtual void selection(int &start, int &index) const
virtual void press(const Event &)
virtual void select(int pos)
virtual void keystroke(const Event &)
virtual void drag(const Event &)
virtual InputHandler * focus_in()
FieldSEditor(const String &sample, WidgetKit *, Style *, FieldSEditorAction *=NULL)
virtual void field(const char *)
virtual void unref() const
#define input(prompt, fmt, var)