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