]> ncurses.scripts.mit.edu Git - ncurses.git/blob - c++/cursslk.h
ncurses 6.2 - patch 20200215
[ncurses.git] / c++ / cursslk.h
1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3  * Copyright 2019,2020 Thomas E. Dickey                                     *
4  * Copyright 1998-2003,2005 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: cursslk.h,v 1.15 2020/02/02 23:34:34 tom Exp $
36
37 #ifndef NCURSES_CURSSLK_H_incl
38 #define NCURSES_CURSSLK_H_incl
39
40 #include <cursesw.h>
41
42 class NCURSES_IMPEXP Soft_Label_Key_Set {
43 public:
44   // This inner class represents the attributes of a Soft Label Key (SLK)
45   class NCURSES_IMPEXP Soft_Label_Key {
46     friend class Soft_Label_Key_Set;
47   public:
48     typedef enum { Left=0, Center=1, Right=2 } Justification;
49
50   private:
51     char *label;           // The Text of the Label
52     Justification format;  // The Justification
53     int num;               // The number of the Label
54
55     Soft_Label_Key() : label(NULL), format(Left), num(-1) {
56     }
57
58     virtual ~Soft_Label_Key() {
59       delete[] label;
60     };
61
62   public:
63     // Set the text of the Label
64     Soft_Label_Key& operator=(char *text);
65
66     // Set the Justification of the Label
67     Soft_Label_Key& operator=(Justification just) {
68       format = just;
69       return *this;
70     }
71
72     // Retrieve the text of the label
73     inline char* operator()(void) const {
74       return label;
75     }
76
77     Soft_Label_Key& operator=(const Soft_Label_Key& rhs)
78     {
79       if (this != &rhs) {
80         *this = rhs;
81       }
82       return *this;
83     }
84
85     Soft_Label_Key(const Soft_Label_Key& rhs)
86       : label(NULL),
87         format(rhs.format),
88         num(rhs.num)
89     {
90       *this = rhs.label;
91     }
92   };
93
94 public:
95   typedef enum {
96     None                = -1,
97     Three_Two_Three     = 0,
98     Four_Four           = 1,
99     PC_Style            = 2,
100     PC_Style_With_Index = 3
101   } Label_Layout;
102
103 private:
104   static long NCURSES_IMPEXP count;               // Number of Key Sets
105   static Label_Layout NCURSES_IMPEXP  format;     // Layout of the Key Sets
106   static int  NCURSES_IMPEXP num_labels;          // Number Of Labels in Key Sets
107   bool NCURSES_IMPEXP b_attrInit;                 // Are attributes initialized
108
109   Soft_Label_Key *slk_array;       // The array of SLK's
110
111   // Init the Key Set
112   void init();
113
114   // Activate or Deactivate Label# i, Label counting starts with 1!
115   void activate_label(int i, bool bf=TRUE);
116
117   // Activate of Deactivate all Labels
118   void activate_labels(bool bf);
119
120 protected:
121   inline void Error (const char* msg) const THROWS(NCursesException) {
122     THROW(new NCursesException (msg));
123   }
124
125   // Remove SLK's from screen
126   void clear() {
127     if (ERR==::slk_clear())
128       Error("slk_clear");
129   }
130
131   // Restore them
132   void restore() {
133     if (ERR==::slk_restore())
134       Error("slk_restore");
135   }
136
137 public:
138
139   // Construct a Key Set, use the most comfortable layout as default.
140   // You must create a Soft_Label_Key_Set before you create any object of
141   // the NCursesWindow, NCursesPanel or derived classes. (Actually before
142   // ::initscr() is called).
143   Soft_Label_Key_Set(Label_Layout fmt);
144
145   // This constructor assumes, that you already constructed a Key Set
146   // with a layout by the constructor above. This layout will be reused.
147   NCURSES_IMPEXP Soft_Label_Key_Set();
148
149   Soft_Label_Key_Set& operator=(const Soft_Label_Key_Set& rhs)
150   {
151     if (this != &rhs) {
152       *this = rhs;
153       init();           // allocate a new slk_array[]
154     }
155     return *this;
156   }
157
158   Soft_Label_Key_Set(const Soft_Label_Key_Set& rhs)
159     : b_attrInit(rhs.b_attrInit),
160       slk_array(NULL)
161   {
162     init();             // allocate a new slk_array[]
163   }
164
165   virtual ~Soft_Label_Key_Set() THROWS(NCursesException);
166
167   // Get Label# i. Label counting starts with 1!
168   NCURSES_IMPEXP Soft_Label_Key& operator[](int i);
169
170   // Retrieve number of Labels
171   inline int labels() const { return num_labels; }
172
173   // Refresh the SLK portion of the screen
174   inline void refresh() {
175     if (ERR==::slk_refresh())
176       Error("slk_refresh");
177   }
178
179   // Mark the SLK portion of the screen for refresh, defer actual refresh
180   // until next update call.
181   inline void noutrefresh() {
182     if (ERR==::slk_noutrefresh())
183       Error("slk_noutrefresh");
184   }
185
186   // Mark the whole SLK portion of the screen as modified
187   inline void touch() {
188     if (ERR==::slk_touch())
189       Error("slk_touch");
190   }
191
192   // Activate Label# i
193   inline void show(int i) {
194     activate_label(i,FALSE);
195     activate_label(i,TRUE);
196   }
197
198   // Hide Label# i
199   inline void hide(int i) {
200     activate_label(i,FALSE);
201   }
202
203   // Show all Labels
204   inline void show() {
205     activate_labels(FALSE);
206     activate_labels(TRUE);
207   }
208
209   // Hide all Labels
210   inline void hide() {
211     activate_labels(FALSE);
212   }
213
214   inline void attron(attr_t attrs) {
215     if (ERR==::slk_attron(attrs))
216       Error("slk_attron");
217   }
218
219   inline void attroff(attr_t attrs) {
220     if (ERR==::slk_attroff(attrs))
221       Error("slk_attroff");
222   }
223
224   inline void attrset(attr_t attrs) {
225     if (ERR==::slk_attrset(attrs))
226       Error("slk_attrset");
227   }
228
229   inline void color(short color_pair_number) {
230     if (ERR==::slk_color(color_pair_number))
231       Error("slk_color");
232   }
233
234   inline attr_t attr() const {
235     return ::slk_attr();
236   }
237 };
238
239 #endif /* NCURSES_CURSSLK_H_incl */