jpayne@69: // * This makes emacs happy -*-Mode: C++;-*- jpayne@69: /**************************************************************************** jpayne@69: * Copyright 2019-2020,2021 Thomas E. Dickey * jpayne@69: * Copyright 1998-2005,2011 Free Software Foundation, Inc. * jpayne@69: * * jpayne@69: * Permission is hereby granted, free of charge, to any person obtaining a * jpayne@69: * copy of this software and associated documentation files (the * jpayne@69: * "Software"), to deal in the Software without restriction, including * jpayne@69: * without limitation the rights to use, copy, modify, merge, publish, * jpayne@69: * distribute, distribute with modifications, sublicense, and/or sell * jpayne@69: * copies of the Software, and to permit persons to whom the Software is * jpayne@69: * furnished to do so, subject to the following conditions: * jpayne@69: * * jpayne@69: * The above copyright notice and this permission notice shall be included * jpayne@69: * in all copies or substantial portions of the Software. * jpayne@69: * * jpayne@69: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * jpayne@69: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * jpayne@69: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * jpayne@69: * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * jpayne@69: * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * jpayne@69: * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * jpayne@69: * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * jpayne@69: * * jpayne@69: * Except as contained in this notice, the name(s) of the above copyright * jpayne@69: * holders shall not be used in advertising or otherwise to promote the * jpayne@69: * sale, use or other dealings in this Software without prior written * jpayne@69: * authorization. * jpayne@69: ****************************************************************************/ jpayne@69: jpayne@69: /**************************************************************************** jpayne@69: * Author: Juergen Pfeifer, 1997 * jpayne@69: ****************************************************************************/ jpayne@69: jpayne@69: // $Id: cursesapp.h,v 1.18 2021/06/17 21:26:02 tom Exp $ jpayne@69: jpayne@69: #ifndef NCURSES_CURSESAPP_H_incl jpayne@69: #define NCURSES_CURSESAPP_H_incl jpayne@69: jpayne@69: #include jpayne@69: jpayne@69: #if (defined(_WIN32) || defined(_WIN64)) jpayne@69: # define NCURSES_CXX_MAIN_NAME cursespp_main jpayne@69: # define NCURSES_CXX_MAIN \ jpayne@69: int main(int argc, char *argv[]) { \ jpayne@69: return NCURSES_CXX_MAIN_NAME(argc, argv); \ jpayne@69: } jpayne@69: #else jpayne@69: # define NCURSES_CXX_MAIN_NAME main jpayne@69: #endif jpayne@69: NCURSES_CXX_IMPEXP int NCURSES_CXX_MAIN_NAME(int argc, char *argv[]); jpayne@69: jpayne@69: class NCURSES_CXX_IMPEXP NCursesApplication { jpayne@69: public: jpayne@69: typedef struct _slk_link { // This structure is used to maintain jpayne@69: struct _slk_link* prev; // a stack of SLKs jpayne@69: Soft_Label_Key_Set* SLKs; jpayne@69: } SLK_Link; jpayne@69: private: jpayne@69: static int rinit(NCursesWindow& w); // Internal Init function for title jpayne@69: static NCursesApplication* theApp; // Global ref. to the application jpayne@69: jpayne@69: static SLK_Link* slk_stack; jpayne@69: jpayne@69: protected: jpayne@69: static NCursesWindow* titleWindow; // The Title Window (if any) jpayne@69: jpayne@69: bool b_Colors; // Is this a color application? jpayne@69: NCursesWindow* Root_Window; // This is the stdscr equiv. jpayne@69: jpayne@69: // Initialization of attributes; jpayne@69: // Rewrite this in your derived class if you prefer other settings jpayne@69: virtual void init(bool bColors); jpayne@69: jpayne@69: // The number of lines for the title window. Default is no title window jpayne@69: // You may rewrite this in your derived class jpayne@69: virtual int titlesize() const { jpayne@69: return 0; jpayne@69: } jpayne@69: jpayne@69: // This method is called to put something into the title window initially jpayne@69: // You may rewrite this in your derived class jpayne@69: virtual void title() { jpayne@69: } jpayne@69: jpayne@69: // The layout used for the Soft Label Keys. Default is to have no SLKs. jpayne@69: // You may rewrite this in your derived class jpayne@69: virtual Soft_Label_Key_Set::Label_Layout useSLKs() const { jpayne@69: return Soft_Label_Key_Set::None; jpayne@69: } jpayne@69: jpayne@69: // This method is called to initialize the SLKs. Default is nothing. jpayne@69: // You may rewrite this in your derived class jpayne@69: virtual void init_labels(Soft_Label_Key_Set& S) const { jpayne@69: (void) S; jpayne@69: } jpayne@69: jpayne@69: // Your derived class must implement this method. The return value must jpayne@69: // be the exit value of your application. jpayne@69: virtual int run() = 0; jpayne@69: jpayne@69: // The constructor is protected, so you may use it in your derived jpayne@69: // class constructor. The argument tells whether or not you want colors. jpayne@69: NCursesApplication(bool wantColors = FALSE); jpayne@69: jpayne@69: NCursesApplication& operator=(const NCursesApplication& rhs) jpayne@69: { jpayne@69: if (this != &rhs) { jpayne@69: *this = rhs; jpayne@69: } jpayne@69: return *this; jpayne@69: } jpayne@69: jpayne@69: NCursesApplication(const NCursesApplication& rhs) jpayne@69: : b_Colors(rhs.b_Colors), jpayne@69: Root_Window(rhs.Root_Window) jpayne@69: { jpayne@69: } jpayne@69: jpayne@69: static NCursesWindow *&getTitleWindow(); jpayne@69: jpayne@69: public: jpayne@69: virtual ~NCursesApplication() THROWS(NCursesException); jpayne@69: jpayne@69: // Get a pointer to the current application object jpayne@69: static NCursesApplication* getApplication(); jpayne@69: jpayne@69: // This method runs the application and returns its exit value jpayne@69: int operator()(void); jpayne@69: jpayne@69: // Process the commandline arguments. The default implementation simply jpayne@69: // ignores them. Your derived class may rewrite this. jpayne@69: virtual void handleArgs(int argc, char* argv[]) { jpayne@69: (void) argc; jpayne@69: (void) argv; jpayne@69: } jpayne@69: jpayne@69: // Does this application use colors? jpayne@69: inline bool useColors() const { jpayne@69: return b_Colors; jpayne@69: } jpayne@69: jpayne@69: // Push the Key Set S onto the SLK Stack. S then becomes the current set jpayne@69: // of Soft Labelled Keys. jpayne@69: void push(Soft_Label_Key_Set& S); jpayne@69: jpayne@69: // Throw away the current set of SLKs and make the previous one the jpayne@69: // new current set. jpayne@69: bool pop(); jpayne@69: jpayne@69: // Retrieve the current set of Soft Labelled Keys. jpayne@69: Soft_Label_Key_Set* top() const; jpayne@69: jpayne@69: // Attributes to use for menu and forms foregrounds jpayne@69: virtual chtype foregrounds() const { jpayne@69: return b_Colors ? static_cast(COLOR_PAIR(1)) : A_BOLD; jpayne@69: } jpayne@69: jpayne@69: // Attributes to use for menu and forms backgrounds jpayne@69: virtual chtype backgrounds() const { jpayne@69: return b_Colors ? static_cast(COLOR_PAIR(2)) : A_NORMAL; jpayne@69: } jpayne@69: jpayne@69: // Attributes to use for inactive (menu) elements jpayne@69: virtual chtype inactives() const { jpayne@69: return b_Colors ? static_cast(COLOR_PAIR(3)|A_DIM) : A_DIM; jpayne@69: } jpayne@69: jpayne@69: // Attributes to use for (form) labels and SLKs jpayne@69: virtual chtype labels() const { jpayne@69: return b_Colors ? static_cast(COLOR_PAIR(4)) : A_NORMAL; jpayne@69: } jpayne@69: jpayne@69: // Attributes to use for form backgrounds jpayne@69: virtual chtype dialog_backgrounds() const { jpayne@69: return b_Colors ? static_cast(COLOR_PAIR(4)) : A_NORMAL; jpayne@69: } jpayne@69: jpayne@69: // Attributes to use as default for (form) window backgrounds jpayne@69: virtual chtype window_backgrounds() const { jpayne@69: return b_Colors ? static_cast(COLOR_PAIR(5)) : A_NORMAL; jpayne@69: } jpayne@69: jpayne@69: // Attributes to use for the title window jpayne@69: virtual chtype screen_titles() const { jpayne@69: return b_Colors ? static_cast(COLOR_PAIR(6)) : A_BOLD; jpayne@69: } jpayne@69: jpayne@69: }; jpayne@69: jpayne@69: #endif /* NCURSES_CURSESAPP_H_incl */