X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=c%2B%2B%2Fdemo.cc;h=7d300ff38b4e43015ce6dfef48b7d3ad7b20092e;hb=75a9c36c205ebefe07580acd0b1053a2abbd44b9;hp=ddd5f2b3e10d5ca6a86d14cc573cdcb5590c97ab;hpb=8f527f87c0b979d9c2598ef5c3394463af288468;p=ncurses.git diff --git a/c++/demo.cc b/c++/demo.cc index ddd5f2b3..7d300ff3 100644 --- a/c++/demo.cc +++ b/c++/demo.cc @@ -1,6 +1,7 @@ // * This makes emacs happy -*-Mode: C++;-*- /**************************************************************************** - * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * + * Copyright 2018-2021,2023 Thomas E. Dickey * + * Copyright 1998-2012,2017 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 * @@ -35,7 +36,7 @@ * Demo code for NCursesMenu and NCursesForm written by * Juergen Pfeifer * - * $Id: demo.cc,v 1.38 2008/08/04 17:16:57 tom Exp $ + * $Id: demo.cc,v 1.52 2023/08/26 19:14:14 tom Exp $ */ #include "internal.h" @@ -43,7 +44,13 @@ #include "cursesm.h" #include "cursesf.h" +#if (defined(_WIN32) || defined(_WIN64)) +#undef KEY_EVENT +#undef sleep +#define sleep(n) Sleep(n) +#else extern "C" unsigned int sleep(unsigned int); +#endif #undef index // needed for NeXT @@ -98,7 +105,7 @@ class SillyDemo } // A refresh to any valid panel updates all panels and refreshes - // the screen. Using mystd is just convenient - We know it's always + // the screen. Using mystd is just convenient - We know it is always // valid until the end of the program. mystd->refresh(); @@ -162,7 +169,7 @@ public: // // ------------------------------------------------------------------------- // -template class MyAction : public NCursesUserItem +template class NCURSES_CXX_IMPEXP MyAction : public NCursesUserItem { public: MyAction (const char* p_name, @@ -170,7 +177,7 @@ public: : NCursesUserItem(p_name, static_cast(0), p_UserData) {} - virtual ~MyAction() {} + virtual ~MyAction() THROWS(NCursesException) {} bool action() { SillyDemo a; @@ -179,9 +186,6 @@ public: } }; -template class MyAction; -template class NCURSES_IMPEXP NCursesUserItem; - class QuitItem : public NCursesMenuItem { public: @@ -214,6 +218,7 @@ private: int chk; protected: bool field_check(NCursesFormField& f) { + (void) f; return TRUE; } bool char_check(int c) { @@ -288,7 +293,7 @@ public: { } - ~TestForm() { + ~TestForm() THROWS(NCursesException) { delete mft; delete ift; delete eft; @@ -313,7 +318,7 @@ public: for(int i=1; i <= S->labels(); i++) { char buf[8]; assert(i < 100); - ::sprintf(buf, "Frm%02d", i); + ::_nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf)) "Frm%02d", i % 100); (*S)[i] = buf; // Text (*S)[i] = Soft_Label_Key_Set::Soft_Label_Key::Left; // Justification } @@ -466,7 +471,7 @@ public: { } - ~MyMenu() + ~MyMenu() THROWS(NCursesException) { P->hide(); delete P; @@ -533,7 +538,7 @@ void TestApplication::init_labels(Soft_Label_Key_Set& S) const for(int i=1; i <= S.labels(); i++) { char buf[8]; assert(i < 100); - ::sprintf(buf, "Key%02d", i); + ::_nc_SPRINTF(buf, _nc_SLIMIT(sizeof(buf)) "Key%02d", i % 100); S[i] = buf; // Text S[i] = Soft_Label_Key_Set::Soft_Label_Key::Left; // Justification } @@ -544,9 +549,9 @@ 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, titleText); - titleWindow->noutrefresh(); + getTitleWindow()->bkgd(screen_titles()); + getTitleWindow()->addstr(0, (getTitleWindow()->cols() - len)/2, titleText); + getTitleWindow()->noutrefresh(); } @@ -561,3 +566,8 @@ int TestApplication::run() // ------------------------------------------------------------------------- // static TestApplication *Demo = new TestApplication(); + +#if (defined(_WIN32) || defined(_WIN64)) +// This is actually only needed when ncurses is a dll +NCURSES_CXX_MAIN +#endif