X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=c%2B%2B%2Fdemo.cc;h=047e4b2473db1f64e08b6db295179da3b65f5715;hb=46722468f47c2b77b3987729b4bcf2321cccfd01;hp=088dc2fbc86dc810e6deeadeab303cf15a7e5b74;hpb=c633e5103a29a38532cf1925257b91cea33fd090;p=ncurses.git diff --git a/c++/demo.cc b/c++/demo.cc index 088dc2fb..047e4b24 100644 --- a/c++/demo.cc +++ b/c++/demo.cc @@ -4,9 +4,10 @@ * written by Anatoly Ivasyuk (anatoly@nick.csh.rit.edu) * * Demo code for NCursesMenu and NCursesForm written by - * Juergen Pfeifer + * Juergen Pfeifer + * Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en * - * $Id: demo.cc,v 1.18 1999/09/11 18:57:54 tom Exp $ + * $Id: demo.cc,v 1.22 2002/07/06 15:47:52 juergen Exp $ */ #include "cursesapp.h" @@ -19,7 +20,7 @@ extern "C" unsigned int sleep(unsigned int); -#undef index // needed for NeXT +#undef index // needed for NeXT // // ------------------------------------------------------------------------- @@ -140,7 +141,7 @@ template class MyAction : public NCursesUserItem { public: MyAction (const char* p_name, - const T* p_UserData) + const T* p_UserData) : NCursesUserItem(p_name, (const char*)0, p_UserData) {}; @@ -170,7 +171,7 @@ class Label : public NCursesFormField { public: Label(const char* title, - int row, int col) + int row, int col) : NCursesFormField(1,(int)::strlen(title),row,col) { set_value(title); options_off(O_EDIT|O_ACTIVE); @@ -293,18 +294,18 @@ public: for (int i=0; i < PADSIZE; i++) { for (int j=0; j < PADSIZE; j++) { - if (i % GRIDSIZE == 0 && j % GRIDSIZE == 0) { - if (i==0 || j==0) - FP.addch('+'); - else - FP.addch((chtype)('A' + (gridcount++ % 26))); - } - else if (i % GRIDSIZE == 0) - FP.addch('-'); - else if (j % GRIDSIZE == 0) - FP.addch('|'); - else - FP.addch(' '); + if (i % GRIDSIZE == 0 && j % GRIDSIZE == 0) { + if (i==0 || j==0) + FP.addch('+'); + else + FP.addch((chtype)('A' + (gridcount++ % 26))); + } + else if (i % GRIDSIZE == 0) + FP.addch('-'); + else if (j % GRIDSIZE == 0) + FP.addch('|'); + else + FP.addch(' '); } } @@ -324,6 +325,49 @@ public: options_off(O_SELECTABLE); } }; + +// +// ------------------------------------------------------------------------- +// +class ScanAction : public NCursesMenuItem +{ +public: + ScanAction(const char* s) : NCursesMenuItem(s) { + } + + bool action() { + NCursesPanel *std = new NCursesPanel(); + + NCursesPanel *w = new NCursesPanel(std->lines() - 2, std->cols() - 2, 1, 1); + w->box(); + w->refresh(); + + NCursesPanel *s = new NCursesPanel(w->lines() - 6, w->cols() - 6, 3, 3); + s->scrollok(TRUE); + ::echo(); + + s->printw("Enter decimal integers. The running total will be shown\n"); + int value = -1; + int result = 0; + while (value != 0) { + value = 0; + s->scanw("%d", &value); + if (value != 0) { + s->printw("%d: ", result += value); + } + s->refresh(); + } + s->printw("\nPress any key to continue..."); + s->getch(); + + delete s; + delete w; + delete std; + ::noecho(); + return FALSE; + } +}; + // // ------------------------------------------------------------------------- // @@ -346,7 +390,7 @@ public: I[2] = new MyAction ("Silly", u); I[3] = new FormAction("Form"); I[4] = new PadAction("Pad"); - I[5] = new PassiveItem("Six"); + I[5] = new ScanAction("Scan"); I[6] = new QuitItem(); I[7] = new NCursesMenuItem(); // Terminating empty item