]> ncurses.scripts.mit.edu Git - ncurses.git/blob - c++/cursslk.h
ncurses 6.2 - patch 20210612
[ncurses.git] / c++ / cursslk.h
1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 // vile:cppmode
3 /****************************************************************************
4  * Copyright 2019-2020,2021 Thomas E. Dickey                                *
5  * Copyright 1998-2003,2005 Free Software Foundation, Inc.                  *
6  *                                                                          *
7  * Permission is hereby granted, free of charge, to any person obtaining a  *
8  * copy of this software and associated documentation files (the            *
9  * "Software"), to deal in the Software without restriction, including      *
10  * without limitation the rights to use, copy, modify, merge, publish,      *
11  * distribute, distribute with modifications, sublicense, and/or sell       *
12  * copies of the Software, and to permit persons to whom the Software is    *
13  * furnished to do so, subject to the following conditions:                 *
14  *                                                                          *
15  * The above copyright notice and this permission notice shall be included  *
16  * in all copies or substantial portions of the Software.                   *
17  *                                                                          *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
21  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
22  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
23  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
24  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
25  *                                                                          *
26  * Except as contained in this notice, the name(s) of the above copyright   *
27  * holders shall not be used in advertising or otherwise to promote the     *
28  * sale, use or other dealings in this Software without prior written       *
29  * authorization.                                                           *
30  ****************************************************************************/
31
32 /****************************************************************************
33  *   Author: Juergen Pfeifer, 1997                                          *
34  ****************************************************************************/
35
36 // $Id: cursslk.h,v 1.19 2021/04/17 18:11:08 tom Exp $
37
38 #ifndef NCURSES_CURSSLK_H_incl
39 #define NCURSES_CURSSLK_H_incl
40
41 #include <cursesw.h>
42
43 class NCURSES_CXX_IMPEXP Soft_Label_Key_Set {
44 public:
45   // This inner class represents the attributes of a Soft Label Key (SLK)
46   class NCURSES_CXX_IMPEXP Soft_Label_Key {
47     friend class Soft_Label_Key_Set;
48   public:
49     typedef enum { Left=0, Center=1, Right=2 } Justification;
50
51   private:
52     char *label;           // The Text of the Label
53     Justification format;  // The Justification
54     int num;               // The number of the Label
55
56     Soft_Label_Key() : label(NULL), format(Left), num(-1) {
57     }
58
59     virtual ~Soft_Label_Key() {
60       delete[] label;
61     };
62
63   public:
64     // Set the text of the Label
65     Soft_Label_Key& operator=(char *text);
66
67     // Set the Justification of the Label
68     Soft_Label_Key& operator=(Justification just) {
69       format = just;
70       return *this;
71     }
72
73     // Retrieve the text of the label
74     inline char* operator()(void) const {
75       return label;
76     }
77
78     Soft_Label_Key& operator=(const Soft_Label_Key& rhs)
79     {
80       if (this != &rhs) {
81         *this = rhs;
82       }
83       return *this;
84     }
85
86     Soft_Label_Key(const Soft_Label_Key& rhs)
87       : label(NULL),
88         format(rhs.format),
89         num(rhs.num)
90     {
91       *this = rhs.label;
92     }
93   };
94
95 public:
96   typedef enum {
97     None                = -1,
98     Three_Two_Three     = 0,
99     Four_Four           = 1,
100     PC_Style            = 2,
101     PC_Style_With_Index = 3
102   } Label_Layout;
103
104 private:
105   static long count;               // Number of Key Sets
106   static Label_Layout  format;     // Layout of the Key Sets
107   static int  num_labels;          // Number Of Labels in Key Sets
108   bool b_attrInit;                 // Are attributes initialized
109
110   Soft_Label_Key *slk_array;       // The array of SLK's
111
112   // Init the Key Set
113   void init();
114
115   // Activate or Deactivate Label# i, Label counting starts with 1!
116   void activate_label(int i, bool bf=TRUE);
117
118   // Activate of Deactivate all Labels
119   void activate_labels(bool bf);
120
121 protected:
122   inline void Error (const char* msg) const THROWS(NCursesException) {
123     THROW(new NCursesException (msg));
124   }
125
126   // Remove SLK's from screen
127   void clear() {
128     if (ERR==::slk_clear())
129       Error("slk_clear");
130   }
131
132   // Restore them
133   void restore() {
134     if (ERR==::slk_restore())
135       Error("slk_restore");
136   }
137
138 public:
139
140   // Construct a Key Set, use the most comfortable layout as default.
141   // You must create a Soft_Label_Key_Set before you create any object of
142   // the NCursesWindow, NCursesPanel or derived classes. (Actually before
143   // ::initscr() is called).
144   explicit Soft_Label_Key_Set(Label_Layout fmt);
145
146   // This constructor assumes, that you already constructed a Key Set
147   // with a layout by the constructor above. This layout will be reused.
148   Soft_Label_Key_Set();
149
150   Soft_Label_Key_Set& operator=(const Soft_Label_Key_Set& rhs)
151   {
152     if (this != &rhs) {
153       *this = rhs;
154       init();           // allocate a new slk_array[]
155     }
156     return *this;
157   }
158
159   Soft_Label_Key_Set(const Soft_Label_Key_Set& rhs)
160     : b_attrInit(rhs.b_attrInit),
161       slk_array(NULL)
162   {
163     init();             // allocate a new slk_array[]
164   }
165
166   virtual ~Soft_Label_Key_Set() THROWS(NCursesException);
167
168   // Get Label# i. Label counting starts with 1!
169   Soft_Label_Key& operator[](int i);
170
171   // Retrieve number of Labels
172   int labels() const;
173
174   // Refresh the SLK portion of the screen
175   inline void refresh() {
176     if (ERR==::slk_refresh())
177       Error("slk_refresh");
178   }
179
180   // Mark the SLK portion of the screen for refresh, defer actual refresh
181   // until next update call.
182   inline void noutrefresh() {
183     if (ERR==::slk_noutrefresh())
184       Error("slk_noutrefresh");
185   }
186
187   // Mark the whole SLK portion of the screen as modified
188   inline void touch() {
189     if (ERR==::slk_touch())
190       Error("slk_touch");
191   }
192
193   // Activate Label# i
194   inline void show(int i) {
195     activate_label(i,FALSE);
196     activate_label(i,TRUE);
197   }
198
199   // Hide Label# i
200   inline void hide(int i) {
201     activate_label(i,FALSE);
202   }
203
204   // Show all Labels
205   inline void show() {
206     activate_labels(FALSE);
207     activate_labels(TRUE);
208   }
209
210   // Hide all Labels
211   inline void hide() {
212     activate_labels(FALSE);
213   }
214
215   inline void attron(attr_t attrs) {
216     if (ERR==::slk_attron(attrs))
217       Error("slk_attron");
218   }
219
220   inline void attroff(attr_t attrs) {
221     if (ERR==::slk_attroff(attrs))
222       Error("slk_attroff");
223   }
224
225   inline void attrset(attr_t attrs) {
226     if (ERR==::slk_attrset(attrs))
227       Error("slk_attrset");
228   }
229
230   inline void color(short color_pair_number) {
231     if (ERR==::slk_color(color_pair_number))
232       Error("slk_color");
233   }
234
235   inline attr_t attr() const {
236     return ::slk_attr();
237   }
238 };
239
240 #endif /* NCURSES_CURSSLK_H_incl */