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