Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:29:42

0001 // * This makes emacs happy -*-Mode: C++;-*-
0002 /****************************************************************************
0003  * Copyright 2019-2020,2021 Thomas E. Dickey                                *
0004  * Copyright 1998-2005,2011 Free Software Foundation, Inc.                  *
0005  *                                                                          *
0006  * Permission is hereby granted, free of charge, to any person obtaining a  *
0007  * copy of this software and associated documentation files (the            *
0008  * "Software"), to deal in the Software without restriction, including      *
0009  * without limitation the rights to use, copy, modify, merge, publish,      *
0010  * distribute, distribute with modifications, sublicense, and/or sell       *
0011  * copies of the Software, and to permit persons to whom the Software is    *
0012  * furnished to do so, subject to the following conditions:                 *
0013  *                                                                          *
0014  * The above copyright notice and this permission notice shall be included  *
0015  * in all copies or substantial portions of the Software.                   *
0016  *                                                                          *
0017  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
0018  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
0019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
0020  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
0021  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
0022  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
0023  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
0024  *                                                                          *
0025  * Except as contained in this notice, the name(s) of the above copyright   *
0026  * holders shall not be used in advertising or otherwise to promote the     *
0027  * sale, use or other dealings in this Software without prior written       *
0028  * authorization.                                                           *
0029  ****************************************************************************/
0030 
0031 /****************************************************************************
0032  *   Author: Juergen Pfeifer, 1997                                          *
0033  ****************************************************************************/
0034 
0035 // $Id: cursesapp.h,v 1.18 2021/06/17 21:26:02 tom Exp $
0036 
0037 #ifndef NCURSES_CURSESAPP_H_incl
0038 #define NCURSES_CURSESAPP_H_incl
0039 
0040 #include <ncursesw/cursslk.h>
0041 
0042 #if (defined(_WIN32) || defined(_WIN64))
0043 # define NCURSES_CXX_MAIN_NAME cursespp_main
0044 # define NCURSES_CXX_MAIN \
0045   int main(int argc, char *argv[]) { \
0046     return NCURSES_CXX_MAIN_NAME(argc, argv); \
0047   }
0048 #else
0049 # define NCURSES_CXX_MAIN_NAME main
0050 #endif
0051 NCURSES_CXX_IMPEXP int NCURSES_CXX_MAIN_NAME(int argc, char *argv[]);
0052 
0053 class NCURSES_CXX_IMPEXP NCursesApplication {
0054 public:
0055   typedef struct _slk_link {          // This structure is used to maintain
0056     struct _slk_link* prev;           // a stack of SLKs
0057     Soft_Label_Key_Set* SLKs;
0058   } SLK_Link;
0059 private:
0060   static int rinit(NCursesWindow& w); // Internal Init function for title
0061   static NCursesApplication* theApp;  // Global ref. to the application
0062 
0063   static SLK_Link* slk_stack;
0064 
0065 protected:
0066   static NCursesWindow* titleWindow;  // The Title Window (if any)
0067 
0068   bool b_Colors;                      // Is this a color application?
0069   NCursesWindow* Root_Window;         // This is the stdscr equiv.
0070 
0071   // Initialization of attributes;
0072   // Rewrite this in your derived class if you prefer other settings
0073   virtual void init(bool bColors);
0074 
0075   // The number of lines for the title window. Default is no title window
0076   // You may rewrite this in your derived class
0077   virtual int titlesize() const {
0078     return 0;
0079   }
0080 
0081   // This method is called to put something into the title window initially
0082   // You may rewrite this in your derived class
0083   virtual void title() {
0084   }
0085 
0086   // The layout used for the Soft Label Keys. Default is to have no SLKs.
0087   // You may rewrite this in your derived class
0088   virtual Soft_Label_Key_Set::Label_Layout useSLKs() const {
0089     return Soft_Label_Key_Set::None;
0090   }
0091 
0092   // This method is called to initialize the SLKs. Default is nothing.
0093   // You may rewrite this in your derived class
0094   virtual void init_labels(Soft_Label_Key_Set& S) const {
0095     (void) S;
0096   }
0097 
0098   // Your derived class must implement this method. The return value must
0099   // be the exit value of your application.
0100   virtual int run() = 0;
0101 
0102   // The constructor is protected, so you may use it in your derived
0103   // class constructor. The argument tells whether or not you want colors.
0104   NCursesApplication(bool wantColors = FALSE);
0105 
0106   NCursesApplication& operator=(const NCursesApplication& rhs)
0107   {
0108     if (this != &rhs) {
0109       *this = rhs;
0110     }
0111     return *this;
0112   }
0113 
0114   NCursesApplication(const NCursesApplication& rhs)
0115     : b_Colors(rhs.b_Colors),
0116       Root_Window(rhs.Root_Window)
0117   {
0118   }
0119 
0120   static NCursesWindow *&getTitleWindow();
0121 
0122 public:
0123   virtual ~NCursesApplication() THROWS(NCursesException);
0124 
0125   // Get a pointer to the current application object
0126   static NCursesApplication* getApplication();
0127 
0128   // This method runs the application and returns its exit value
0129   int operator()(void);
0130 
0131   // Process the commandline arguments. The default implementation simply
0132   // ignores them. Your derived class may rewrite this.
0133   virtual void handleArgs(int argc, char* argv[]) {
0134     (void) argc;
0135     (void) argv;
0136   }
0137 
0138   // Does this application use colors?
0139   inline bool useColors() const {
0140     return b_Colors;
0141   }
0142 
0143   // Push the Key Set S onto the SLK Stack. S then becomes the current set
0144   // of Soft Labelled Keys.
0145   void push(Soft_Label_Key_Set& S);
0146 
0147   // Throw away the current set of SLKs and make the previous one the
0148   // new current set.
0149   bool pop();
0150 
0151   // Retrieve the current set of Soft Labelled Keys.
0152   Soft_Label_Key_Set* top() const;
0153 
0154   // Attributes to use for menu and forms foregrounds
0155   virtual chtype foregrounds() const {
0156     return b_Colors ? static_cast<chtype>(COLOR_PAIR(1)) : A_BOLD;
0157   }
0158 
0159   // Attributes to use for menu and forms backgrounds
0160   virtual chtype backgrounds() const {
0161     return b_Colors ? static_cast<chtype>(COLOR_PAIR(2)) : A_NORMAL;
0162   }
0163 
0164   // Attributes to use for inactive (menu) elements
0165   virtual chtype inactives() const {
0166     return b_Colors ? static_cast<chtype>(COLOR_PAIR(3)|A_DIM) : A_DIM;
0167   }
0168 
0169   // Attributes to use for (form) labels and SLKs
0170   virtual chtype labels() const {
0171     return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL;
0172   }
0173 
0174   // Attributes to use for form backgrounds
0175   virtual chtype dialog_backgrounds() const {
0176     return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL;
0177   }
0178 
0179   // Attributes to use as default for (form) window backgrounds
0180   virtual chtype window_backgrounds() const {
0181     return b_Colors ? static_cast<chtype>(COLOR_PAIR(5)) : A_NORMAL;
0182   }
0183 
0184   // Attributes to use for the title window
0185   virtual chtype screen_titles() const {
0186     return b_Colors ? static_cast<chtype>(COLOR_PAIR(6)) : A_BOLD;
0187   }
0188 
0189 };
0190 
0191 #endif /* NCURSES_CURSESAPP_H_incl */