Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | // * This makes emacs happy -*-Mode: C++;-*- |
| 2 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 3 | * Copyright 2019-2020,2021 Thomas E. Dickey * |
| 4 | * Copyright 1998-2005,2011 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 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 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 35 | // $Id: cursesapp.h,v 1.18 2021/06/17 21:26:02 tom Exp $ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 36 | |
| 37 | #ifndef NCURSES_CURSESAPP_H_incl |
| 38 | #define NCURSES_CURSESAPP_H_incl |
| 39 | |
| 40 | #include <cursslk.h> |
| 41 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 42 | #if (defined(_WIN32) || defined(_WIN64)) |
| 43 | # define NCURSES_CXX_MAIN_NAME cursespp_main |
| 44 | # define NCURSES_CXX_MAIN \ |
| 45 | int main(int argc, char *argv[]) { \ |
| 46 | return NCURSES_CXX_MAIN_NAME(argc, argv); \ |
| 47 | } |
| 48 | #else |
| 49 | # define NCURSES_CXX_MAIN_NAME main |
| 50 | #endif |
| 51 | NCURSES_CXX_IMPEXP int NCURSES_CXX_MAIN_NAME(int argc, char *argv[]); |
| 52 | |
| 53 | class NCURSES_CXX_IMPEXP NCursesApplication { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 54 | public: |
| 55 | typedef struct _slk_link { // This structure is used to maintain |
| 56 | struct _slk_link* prev; // a stack of SLKs |
| 57 | Soft_Label_Key_Set* SLKs; |
| 58 | } SLK_Link; |
| 59 | private: |
| 60 | static int rinit(NCursesWindow& w); // Internal Init function for title |
| 61 | static NCursesApplication* theApp; // Global ref. to the application |
| 62 | |
| 63 | static SLK_Link* slk_stack; |
| 64 | |
| 65 | protected: |
| 66 | static NCursesWindow* titleWindow; // The Title Window (if any) |
| 67 | |
| 68 | bool b_Colors; // Is this a color application? |
| 69 | NCursesWindow* Root_Window; // This is the stdscr equiv. |
| 70 | |
| 71 | // Initialization of attributes; |
| 72 | // Rewrite this in your derived class if you prefer other settings |
| 73 | virtual void init(bool bColors); |
| 74 | |
| 75 | // The number of lines for the title window. Default is no title window |
| 76 | // You may rewrite this in your derived class |
| 77 | virtual int titlesize() const { |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | // This method is called to put something into the title window initially |
| 82 | // You may rewrite this in your derived class |
| 83 | virtual void title() { |
| 84 | } |
| 85 | |
| 86 | // The layout used for the Soft Label Keys. Default is to have no SLKs. |
| 87 | // You may rewrite this in your derived class |
| 88 | virtual Soft_Label_Key_Set::Label_Layout useSLKs() const { |
| 89 | return Soft_Label_Key_Set::None; |
| 90 | } |
| 91 | |
| 92 | // This method is called to initialize the SLKs. Default is nothing. |
| 93 | // You may rewrite this in your derived class |
| 94 | virtual void init_labels(Soft_Label_Key_Set& S) const { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 95 | (void) S; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | // Your derived class must implement this method. The return value must |
| 99 | // be the exit value of your application. |
| 100 | virtual int run() = 0; |
| 101 | |
| 102 | // The constructor is protected, so you may use it in your derived |
| 103 | // class constructor. The argument tells whether or not you want colors. |
| 104 | NCursesApplication(bool wantColors = FALSE); |
| 105 | |
| 106 | NCursesApplication& operator=(const NCursesApplication& rhs) |
| 107 | { |
| 108 | if (this != &rhs) { |
| 109 | *this = rhs; |
| 110 | } |
| 111 | return *this; |
| 112 | } |
| 113 | |
| 114 | NCursesApplication(const NCursesApplication& rhs) |
| 115 | : b_Colors(rhs.b_Colors), |
| 116 | Root_Window(rhs.Root_Window) |
| 117 | { |
| 118 | } |
| 119 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 120 | static NCursesWindow *&getTitleWindow(); |
| 121 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 122 | public: |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 123 | virtual ~NCursesApplication() THROWS(NCursesException); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 124 | |
| 125 | // Get a pointer to the current application object |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 126 | static NCursesApplication* getApplication(); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 127 | |
| 128 | // This method runs the application and returns its exit value |
| 129 | int operator()(void); |
| 130 | |
| 131 | // Process the commandline arguments. The default implementation simply |
| 132 | // ignores them. Your derived class may rewrite this. |
| 133 | virtual void handleArgs(int argc, char* argv[]) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 134 | (void) argc; |
| 135 | (void) argv; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // Does this application use colors? |
| 139 | inline bool useColors() const { |
| 140 | return b_Colors; |
| 141 | } |
| 142 | |
| 143 | // Push the Key Set S onto the SLK Stack. S then becomes the current set |
| 144 | // of Soft Labelled Keys. |
| 145 | void push(Soft_Label_Key_Set& S); |
| 146 | |
| 147 | // Throw away the current set of SLKs and make the previous one the |
| 148 | // new current set. |
| 149 | bool pop(); |
| 150 | |
| 151 | // Retrieve the current set of Soft Labelled Keys. |
| 152 | Soft_Label_Key_Set* top() const; |
| 153 | |
| 154 | // Attributes to use for menu and forms foregrounds |
| 155 | virtual chtype foregrounds() const { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 156 | return b_Colors ? static_cast<chtype>(COLOR_PAIR(1)) : A_BOLD; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | // Attributes to use for menu and forms backgrounds |
| 160 | virtual chtype backgrounds() const { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 161 | return b_Colors ? static_cast<chtype>(COLOR_PAIR(2)) : A_NORMAL; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | // Attributes to use for inactive (menu) elements |
| 165 | virtual chtype inactives() const { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 166 | return b_Colors ? static_cast<chtype>(COLOR_PAIR(3)|A_DIM) : A_DIM; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | // Attributes to use for (form) labels and SLKs |
| 170 | virtual chtype labels() const { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 171 | return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | // Attributes to use for form backgrounds |
| 175 | virtual chtype dialog_backgrounds() const { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 176 | return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // Attributes to use as default for (form) window backgrounds |
| 180 | virtual chtype window_backgrounds() const { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 181 | return b_Colors ? static_cast<chtype>(COLOR_PAIR(5)) : A_NORMAL; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // Attributes to use for the title window |
| 185 | virtual chtype screen_titles() const { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 186 | return b_Colors ? static_cast<chtype>(COLOR_PAIR(6)) : A_BOLD; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | }; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 190 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 191 | #endif /* NCURSES_CURSESAPP_H_incl */ |