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