X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=c%2B%2B%2Fdemo.cc;h=1a436b5e2197354053d7385b8751d475013f4593;hp=f3fe3e46f7ef4fe75da1937a712a42de434e8060;hb=0c9774ef662e2137933ac0c79077eaa9c8981357;hpb=a8987e73ec254703634802b4f7ee30d3a485524d diff --git a/c++/demo.cc b/c++/demo.cc index f3fe3e46..1a436b5e 100644 --- a/c++/demo.cc +++ b/c++/demo.cc @@ -1,3 +1,32 @@ +// * This makes emacs happy -*-Mode: C++;-*- +/**************************************************************************** + * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the * + * "Software"), to deal in the Software without restriction, including * + * without limitation the rights to use, copy, modify, merge, publish, * + * distribute, distribute with modifications, sublicense, and/or sell * + * copies of the Software, and to permit persons to whom the Software is * + * furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included * + * in all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * + * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * + * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * + * * + * Except as contained in this notice, the name(s) of the above copyright * + * holders shall not be used in advertising or otherwise to promote the * + * sale, use or other dealings in this Software without prior written * + * authorization. * + ****************************************************************************/ + /* * Silly demo program for the NCursesPanel class. * @@ -6,17 +35,14 @@ * Demo code for NCursesMenu and NCursesForm written by * Juergen Pfeifer * - * $Id: demo.cc,v 1.24 2004/01/15 00:21:27 tom Exp $ + * $Id: demo.cc,v 1.35 2007/01/27 20:28:51 tom Exp $ */ +#include "internal.h" #include "cursesapp.h" #include "cursesm.h" #include "cursesf.h" -#if HAVE_LIBC_H -# include -#endif - extern "C" unsigned int sleep(unsigned int); #undef index // needed for NeXT @@ -141,10 +167,10 @@ template class MyAction : public NCursesUserItem public: MyAction (const char* p_name, const T* p_UserData) - : NCursesUserItem(p_name, (const char*)0, p_UserData) - {}; + : NCursesUserItem(p_name, static_cast(0), p_UserData) + {} - ~MyAction() {} + virtual ~MyAction() {} bool action() { SillyDemo a; @@ -153,6 +179,9 @@ public: } }; +template class MyAction; +template class NCURSES_IMPEXP NCursesUserItem; + class QuitItem : public NCursesMenuItem { public: @@ -171,7 +200,7 @@ class Label : public NCursesFormField public: Label(const char* title, int row, int col) - : NCursesFormField(1,(int)::strlen(title),row,col) { + : NCursesFormField(1, static_cast(::strlen(title)), row, col) { set_value(title); options_off(O_EDIT|O_ACTIVE); } @@ -179,7 +208,8 @@ public: // // ------------------------------------------------------------------------- // -class MyFieldType : public UserDefinedFieldType { +class MyFieldType : public UserDefinedFieldType +{ private: int chk; protected: @@ -207,7 +237,13 @@ private: static const char *weekdays[]; public: - TestForm() : NCursesForm(13,51,(lines()-15)/2,(cols()-53)/2) { + TestForm() + : NCursesForm(13, 51, (lines() - 15)/2, (cols() - 53)/2), + F(0), + mft(0), + ift(0), + eft(0) + { F = new NCursesFormField*[10]; mft = new MyFieldType('X'); @@ -239,6 +275,19 @@ public: F[8]->options_off(O_STATIC); // make field dynamic } + TestForm& operator=(const TestForm& rhs) + { + if (this != &rhs) { + *this = rhs; + } + return *this; + } + + TestForm(const TestForm& rhs) + : NCursesForm(rhs), F(0), mft(0), ift(0), eft(0) + { + } + ~TestForm() { delete mft; delete ift; @@ -248,7 +297,7 @@ public: const char* TestForm::weekdays[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", - "Friday", "Saturday", (const char *)0 }; + "Friday", "Saturday", NULL }; // // ------------------------------------------------------------------------- // @@ -262,7 +311,7 @@ public: TestForm F; Soft_Label_Key_Set* S = new Soft_Label_Key_Set; for(int i=1; i <= S->labels(); i++) { - char buf[5]; + char buf[8]; ::sprintf(buf,"Frm%02d",i); (*S)[i] = buf; // Text (*S)[i] = Soft_Label_Key_Set::Soft_Label_Key::Left; // Justification @@ -297,7 +346,7 @@ public: if (i==0 || j==0) FP.addch('+'); else - FP.addch((chtype)('A' + (gridcount++ % 26))); + FP.addch(static_cast('A' + (gridcount++ % 26))); } else if (i % GRIDSIZE == 0) FP.addch('-'); @@ -318,7 +367,8 @@ public: // // ------------------------------------------------------------------------- // -class PassiveItem : public NCursesMenuItem { +class PassiveItem : public NCursesMenuItem +{ public: PassiveItem(const char* text) : NCursesMenuItem(text) { options_off(O_SELECTABLE); @@ -346,13 +396,13 @@ public: ::echo(); s->printw("Enter decimal integers. The running total will be shown\n"); - int value = -1; + int nvalue = -1; int result = 0; - while (value != 0) { - value = 0; - s->scanw("%d", &value); - if (value != 0) { - s->printw("%d: ", result += value); + while (nvalue != 0) { + nvalue = 0; + s->scanw("%d", &nvalue); + if (nvalue != 0) { + s->printw("%d: ", result += nvalue); } s->refresh(); } @@ -380,7 +430,8 @@ private: public: MyMenu () - : NCursesMenu (n_items+2, 8, (lines()-10)/2, (cols()-10)/2) + : NCursesMenu (n_items+2, 8, (lines()-10)/2, (cols()-10)/2), + P(0), I(0), u(0) { u = new UserData(1); I = new NCursesMenuItem*[1+n_items]; @@ -400,6 +451,19 @@ public: P->show(); } + MyMenu& operator=(const MyMenu& rhs) + { + if (this != &rhs) { + *this = rhs; + } + return *this; + } + + MyMenu(const MyMenu& rhs) + : NCursesMenu(rhs), P(0), I(0), u(0) + { + } + ~MyMenu() { P->hide(); @@ -445,7 +509,8 @@ public: // // ------------------------------------------------------------------------- // -class TestApplication : public NCursesApplication { +class TestApplication : public NCursesApplication +{ protected: int titlesize() const { return 1; } void title(); @@ -461,26 +526,29 @@ public: int run(); }; -void TestApplication::init_labels(Soft_Label_Key_Set& S) const { +void TestApplication::init_labels(Soft_Label_Key_Set& S) const +{ for(int i=1; i <= S.labels(); i++) { - char buf[5]; + char buf[8]; ::sprintf(buf,"Key%02d",i); S[i] = buf; // Text S[i] = Soft_Label_Key_Set::Soft_Label_Key::Left; // Justification } } -void TestApplication::title() { - const char * const title = "Simple C++ Binding Demo"; - const int len = ::strlen(title); +void TestApplication::title() +{ + const char * const titleText = "Simple C++ Binding Demo"; + const int len = ::strlen(titleText); titleWindow->bkgd(screen_titles()); - titleWindow->addstr(0,(titleWindow->cols()-len)/2,title); + titleWindow->addstr(0,(titleWindow->cols() - len)/2, titleText); titleWindow->noutrefresh(); } -int TestApplication::run() { +int TestApplication::run() +{ MyMenu M; M(); return 0; @@ -489,4 +557,4 @@ int TestApplication::run() { // // ------------------------------------------------------------------------- // -static TestApplication Demo; +static TestApplication *Demo = new TestApplication();