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