extern "C" int atoi(const char*); #include #include #include #include #include #include #include #include #include "std-macros.h" static exception Quit; class S : public StringEditor { public: S(Deck* d); boolean HandleChar(char c); protected: void FlipOrQuit(); Deck* d; }; S::S(Deck* d) : StringEditor(new ButtonState(1), " ") { this->d = d; } boolean S::HandleChar(char c) { if (c == '\r') { FlipOrQuit(); return false; } else return StringEditor::HandleChar(c); } void S::FlipOrQuit() { char* t = newstr(Text()); char* tq = strtok(t, " "); if (tq and streq(tq, "q")) throw(Quit, null); else d->FlipTo(atoi(t)); } main () { World* w = new World(); Deck* d; S* s; VBox* vb; d = new Deck(); s = new S(d); vb = new VBox; vb->Align(Center); vb->Insert(d); vb->Insert(s); Message* m2; d->Insert(new Message("hi")); d->Insert(m2 = new Message("there")); d->Insert(new Message("sailor")); d->Insert(new Message("boy")); w->InsertApplication( new Tray(vb)); if (not catch(Quit)) w->Run(); }