]> ncurses.scripts.mit.edu Git - ncurses.git/blob - c++/cursesapp.h
ncurses 6.2 - patch 20200308
[ncurses.git] / c++ / cursesapp.h
1 // * This makes emacs happy -*-Mode: C++;-*-
2 /****************************************************************************
3  * Copyright 2019,2020 Thomas E. Dickey                                     *
4  * Copyright 1998-2005,2011 Free Software Foundation, Inc.                  *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30
31 /****************************************************************************
32  *   Author: Juergen Pfeifer, 1997                                          *
33  ****************************************************************************/
34
35 // $Id: cursesapp.h,v 1.14 2020/02/02 23:34:34 tom Exp $
36
37 #ifndef NCURSES_CURSESAPP_H_incl
38 #define NCURSES_CURSESAPP_H_incl
39
40 #include <cursslk.h>
41
42 class NCURSES_IMPEXP NCursesApplication {
43 public:
44   typedef struct _slk_link {          // This structure is used to maintain
45     struct _slk_link* prev;           // a stack of SLKs
46     Soft_Label_Key_Set* SLKs;
47   } SLK_Link;
48 private:
49   static int rinit(NCursesWindow& w); // Internal Init function for title
50   static NCursesApplication* theApp;  // Global ref. to the application
51
52   static SLK_Link* slk_stack;
53
54 protected:
55   static NCursesWindow* titleWindow;  // The Title Window (if any)
56
57   bool b_Colors;                      // Is this a color application?
58   NCursesWindow* Root_Window;         // This is the stdscr equiv.
59
60   // Initialization of attributes;
61   // Rewrite this in your derived class if you prefer other settings
62   virtual void init(bool bColors);
63
64   // The number of lines for the title window. Default is no title window
65   // You may rewrite this in your derived class
66   virtual int titlesize() const {
67     return 0;
68   }
69
70   // This method is called to put something into the title window initially
71   // You may rewrite this in your derived class
72   virtual void title() {
73   }
74
75   // The layout used for the Soft Label Keys. Default is to have no SLKs.
76   // You may rewrite this in your derived class
77   virtual Soft_Label_Key_Set::Label_Layout useSLKs() const {
78     return Soft_Label_Key_Set::None;
79   }
80
81   // This method is called to initialize the SLKs. Default is nothing.
82   // You may rewrite this in your derived class
83   virtual void init_labels(Soft_Label_Key_Set& S) const {
84     (void) S;
85   }
86
87   // Your derived class must implement this method. The return value must
88   // be the exit value of your application.
89   virtual int run() = 0;
90
91   // The constructor is protected, so you may use it in your derived
92   // class constructor. The argument tells whether or not you want colors.
93   NCursesApplication(bool wantColors = FALSE);
94
95   NCursesApplication& operator=(const NCursesApplication& rhs)
96   {
97     if (this != &rhs) {
98       *this = rhs;
99     }
100     return *this;
101   }
102
103   NCursesApplication(const NCursesApplication& rhs)
104     : b_Colors(rhs.b_Colors),
105       Root_Window(rhs.Root_Window)
106   {
107   }
108
109 public:
110   virtual ~NCursesApplication() THROWS(NCursesException);
111
112   // Get a pointer to the current application object
113   static NCursesApplication* getApplication() {
114     return theApp;
115   }
116
117   // This method runs the application and returns its exit value
118   int operator()(void);
119
120   // Process the commandline arguments. The default implementation simply
121   // ignores them. Your derived class may rewrite this.
122   virtual void handleArgs(int argc, char* argv[]) {
123     (void) argc;
124     (void) argv;
125   }
126
127   // Does this application use colors?
128   inline bool useColors() const {
129     return b_Colors;
130   }
131
132   // Push the Key Set S onto the SLK Stack. S then becomes the current set
133   // of Soft Labelled Keys.
134   void push(Soft_Label_Key_Set& S);
135
136   // Throw away the current set of SLKs and make the previous one the
137   // new current set.
138   bool pop();
139
140   // Retrieve the current set of Soft Labelled Keys.
141   Soft_Label_Key_Set* top() const;
142
143   // Attributes to use for menu and forms foregrounds
144   virtual chtype foregrounds() const {
145     return b_Colors ? static_cast<chtype>(COLOR_PAIR(1)) : A_BOLD;
146   }
147
148   // Attributes to use for menu and forms backgrounds
149   virtual chtype backgrounds() const {
150     return b_Colors ? static_cast<chtype>(COLOR_PAIR(2)) : A_NORMAL;
151   }
152
153   // Attributes to use for inactive (menu) elements
154   virtual chtype inactives() const {
155     return b_Colors ? static_cast<chtype>(COLOR_PAIR(3)|A_DIM) : A_DIM;
156   }
157
158   // Attributes to use for (form) labels and SLKs
159   virtual chtype labels() const {
160     return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL;
161   }
162
163   // Attributes to use for form backgrounds
164   virtual chtype dialog_backgrounds() const {
165     return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL;
166   }
167
168   // Attributes to use as default for (form) window backgrounds
169   virtual chtype window_backgrounds() const {
170     return b_Colors ? static_cast<chtype>(COLOR_PAIR(5)) : A_NORMAL;
171   }
172
173   // Attributes to use for the title window
174   virtual chtype screen_titles() const {
175     return b_Colors ? static_cast<chtype>(COLOR_PAIR(6)) : A_BOLD;
176   }
177
178 };
179  
180 #endif /* NCURSES_CURSESAPP_H_incl */