|
@@ -4,7 +4,53 @@
|
4
|
4
|
#include <string.h>
|
5
|
5
|
#include "core.h"
|
6
|
6
|
|
7
|
|
-extern struct _softlabelkeys *slks;
|
|
7
|
+/** @file
|
|
8
|
+ *
|
|
9
|
+ * Soft label key functions
|
|
10
|
+ */
|
|
11
|
+
|
|
12
|
+#define MIN_SPACE_SIZE 2
|
|
13
|
+
|
|
14
|
+struct _softlabel {
|
|
15
|
+ // label string
|
|
16
|
+ char *label;
|
|
17
|
+ /* Format of soft label
|
|
18
|
+ 0: left justify
|
|
19
|
+ 1: centre justify
|
|
20
|
+ 2: right justify
|
|
21
|
+ */
|
|
22
|
+ unsigned short fmt;
|
|
23
|
+};
|
|
24
|
+
|
|
25
|
+struct _softlabelkeys {
|
|
26
|
+ struct _softlabel fkeys[12];
|
|
27
|
+ attr_t attrs;
|
|
28
|
+ /* Soft label layout format
|
|
29
|
+ 0: 3-2-3
|
|
30
|
+ 1: 4-4
|
|
31
|
+ 2: 4-4-4
|
|
32
|
+ 3: 4-4-4 with index line
|
|
33
|
+ */
|
|
34
|
+ unsigned short fmt;
|
|
35
|
+ unsigned short max_label_len;
|
|
36
|
+ unsigned short maj_space_len;
|
|
37
|
+ unsigned short num_labels;
|
|
38
|
+ unsigned short num_spaces;
|
|
39
|
+ unsigned short *spaces;
|
|
40
|
+};
|
|
41
|
+
|
|
42
|
+struct _softlabelkeys *slks;
|
|
43
|
+
|
|
44
|
+/*
|
|
45
|
+ I either need to break the primitives here, or write a collection of
|
|
46
|
+ functions specifically for SLKs that directly access the screen
|
|
47
|
+ functions - since this technically isn't part of stdscr, I think
|
|
48
|
+ this should be ok...
|
|
49
|
+ */
|
|
50
|
+
|
|
51
|
+static void _movetoslk ( void ) {
|
|
52
|
+ stdscr->scr->movetoyx( stdscr->scr, LINES, 0 );
|
|
53
|
+}
|
8
|
54
|
|
9
|
55
|
/**
|
10
|
56
|
* Return the attribute used for the soft function keys
|
|
@@ -105,12 +151,24 @@ int slk_attr_set ( const attr_t attrs, short colour_pair_number,
|
105
|
151
|
int slk_clear ( void ) {
|
106
|
152
|
if ( slks == NULL )
|
107
|
153
|
return ERR;
|
108
|
|
-
|
109
|
|
- wmove(stdscr,stdscr->height-1,0);
|
110
|
|
- wclrtoeol(stdscr);
|
111
|
154
|
return 0;
|
112
|
155
|
}
|
113
|
156
|
|
|
157
|
+/**
|
|
158
|
+ * Set soft label colour pair
|
|
159
|
+ */
|
|
160
|
+int slk_colour ( short colour_pair_number ) {
|
|
161
|
+ if ( slks == NULL )
|
|
162
|
+ return ERR;
|
|
163
|
+ if ( ( unsigned short )colour_pair_number > COLORS )
|
|
164
|
+ return ERR;
|
|
165
|
+
|
|
166
|
+ slks->attrs = ( (unsigned short)colour_pair_number << CPAIR_SHIFT )
|
|
167
|
+ | ( slks->attrs & A_ATTRIBUTES );
|
|
168
|
+
|
|
169
|
+ return OK;
|
|
170
|
+}
|
|
171
|
+
|
114
|
172
|
/**
|
115
|
173
|
* Initialise the soft function keys
|
116
|
174
|
*
|
|
@@ -118,14 +176,44 @@ int slk_clear ( void ) {
|
118
|
176
|
* @ret rc return status code
|
119
|
177
|
*/
|
120
|
178
|
int slk_init ( int fmt ) {
|
|
179
|
+ unsigned short nmaj, nmin, nblocks, available_width;
|
|
180
|
+
|
121
|
181
|
if ( (unsigned)fmt > 3 ) {
|
122
|
182
|
return ERR;
|
123
|
183
|
}
|
124
|
184
|
|
125
|
185
|
slks = malloc(sizeof(struct _softlabelkeys));
|
126
|
186
|
slks->attrs = A_DEFAULT;
|
127
|
|
- slks->fmt = (unsigned short)fmt;
|
128
|
|
- slks->maxlablen = 5;
|
|
187
|
+ slks->fmt = fmt;
|
|
188
|
+ switch(fmt) {
|
|
189
|
+ case 0:
|
|
190
|
+ nblocks = 8; nmaj = 2; nmin = 5;
|
|
191
|
+ slks->spaces = calloc(2, sizeof(unsigned short));
|
|
192
|
+ slks->spaces[0] = 2; slks->spaces[1] = 4;
|
|
193
|
+ break;
|
|
194
|
+ case 1:
|
|
195
|
+ nblocks = 8; nmaj = 1; nmin = 6;
|
|
196
|
+ slks->spaces = calloc(1, sizeof(unsigned short));
|
|
197
|
+ slks->spaces[0] = 3;
|
|
198
|
+ break;
|
|
199
|
+ case 2:
|
|
200
|
+ // same allocations as format 3
|
|
201
|
+ case 3:
|
|
202
|
+ nblocks = 12; nmaj = 2; nmin = 9;
|
|
203
|
+ slks->spaces = calloc(2, sizeof(unsigned short));
|
|
204
|
+ slks->spaces[0] = 3; slks->spaces[1] = 7;
|
|
205
|
+ break;
|
|
206
|
+ }
|
|
207
|
+
|
|
208
|
+ // determine maximum label length and major space size
|
|
209
|
+ available_width = COLS - ( ( MIN_SPACE_SIZE * nmaj ) + nmin );
|
|
210
|
+ slks->max_label_len = available_width / nblocks;
|
|
211
|
+ slks->maj_space_len = ( available_width % nblocks ) / nmaj;
|
|
212
|
+ slks->num_spaces = nmaj;
|
|
213
|
+
|
|
214
|
+ // strip a line from the screen
|
|
215
|
+ LINES -= 1;
|
|
216
|
+
|
129
|
217
|
return OK;
|
130
|
218
|
}
|
131
|
219
|
|
|
@@ -148,9 +236,34 @@ char* slk_label ( int labnum ) {
|
148
|
236
|
* @ret rc return status code
|
149
|
237
|
*/
|
150
|
238
|
int slk_restore ( void ) {
|
|
239
|
+ unsigned short i, j,
|
|
240
|
+ *next_space, *last_space;
|
|
241
|
+ chtype space_ch;
|
|
242
|
+ char c;
|
|
243
|
+
|
151
|
244
|
if ( slks == NULL )
|
152
|
245
|
return ERR;
|
153
|
246
|
|
|
247
|
+ _movetoslk();
|
|
248
|
+
|
|
249
|
+ space_ch = (int)' ' | slks->attrs;
|
|
250
|
+ next_space = &(slks->spaces[0]);
|
|
251
|
+ last_space = &(slks->spaces[slks->num_spaces-1]);
|
|
252
|
+
|
|
253
|
+ for ( i = 0; i < slks->num_labels ; i++ ) {
|
|
254
|
+ while ( ( c = *(slks->fkeys[i].label++) ) != '\0' ) {
|
|
255
|
+ stdscr->scr->putc( stdscr->scr, (int)c | slks->attrs );
|
|
256
|
+ }
|
|
257
|
+ if ( i == *next_space ) {
|
|
258
|
+ for ( j = 0; j < slks->maj_space_len; j++ )
|
|
259
|
+ stdscr->scr->putc( stdscr->scr, space_ch );
|
|
260
|
+ if ( next_space < last_space )
|
|
261
|
+ next_space++;
|
|
262
|
+ } else {
|
|
263
|
+ stdscr->scr->putc( stdscr->scr, space_ch );
|
|
264
|
+ }
|
|
265
|
+ }
|
|
266
|
+
|
154
|
267
|
return OK;
|
155
|
268
|
}
|
156
|
269
|
|
|
@@ -169,7 +282,7 @@ int slk_set ( int labnum, const char *label, int fmt ) {
|
169
|
282
|
return ERR;
|
170
|
283
|
if ( (unsigned short)fmt >= 3 )
|
171
|
284
|
return ERR;
|
172
|
|
- if ( strlen(label) > slks->maxlablen )
|
|
285
|
+ if ( strlen(label) > slks->max_label_len )
|
173
|
286
|
return ERR;
|
174
|
287
|
|
175
|
288
|
strcpy( slks->fkeys[labnum].label, label );
|