1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright 2019-2022,2023 Thomas E. Dickey *
4 * Copyright 1998-2005,2012 Free Software Foundation, Inc. *
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: *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
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. *
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 *
29 ****************************************************************************/
31 /****************************************************************************
32 * Author: Juergen Pfeifer, 1997 *
33 ****************************************************************************/
37 #include "cursesapp.h"
39 MODULE_ID("$Id: cursslk.cc,v 1.21 2023/02/25 23:36:06 tom Exp $")
41 Soft_Label_Key_Set::Soft_Label_Key&
42 Soft_Label_Key_Set::Soft_Label_Key::operator=(char *text)
45 size_t need = 1 + ::strlen(text);
46 label = new char[need];
47 ::_nc_STRCPY(label,text,need);
51 long Soft_Label_Key_Set::count = 0L;
52 int Soft_Label_Key_Set::num_labels = 0;
54 Soft_Label_Key_Set::Label_Layout
55 Soft_Label_Key_Set::format = None;
57 void Soft_Label_Key_Set::init()
63 slk_array = new Soft_Label_Key[num_labels + 1];
64 for(int i=0; i < num_labels; i++) {
65 slk_array[i].num = i+1;
70 Soft_Label_Key_Set::Soft_Label_Key_Set()
75 Error("No default SLK layout");
79 Soft_Label_Key_Set::Soft_Label_Key_Set(Soft_Label_Key_Set::Label_Layout fmt)
84 Error("Invalid SLK Layout");
87 if (ERR == ::slk_init(static_cast<int>(fmt)))
89 num_labels = (fmt>=PC_Style?12:8);
92 Error("All SLKs must have same layout");
96 Soft_Label_Key_Set::~Soft_Label_Key_Set() THROWS(NCursesException) {
103 Soft_Label_Key_Set::Soft_Label_Key& Soft_Label_Key_Set::operator[](int i) {
104 if (i<1 || i>num_labels)
105 Error("Invalid Label index");
106 return slk_array[i-1];
109 int Soft_Label_Key_Set::labels() const {
113 void Soft_Label_Key_Set::activate_label(int i, bool bf) {
115 NCursesApplication* A = NCursesApplication::getApplication();
116 if (A) attrset(A->labels());
119 Soft_Label_Key& K = (*this)[i];
120 if (ERR==::slk_set(K.num,bf?K.label:"",K.format))
125 void Soft_Label_Key_Set::activate_labels(bool bf)
128 NCursesApplication* A = NCursesApplication::getApplication();
129 if (A) attrset(A->labels());
132 for(int i=1; i <= num_labels; i++) {
133 Soft_Label_Key& K = (*this)[i];
134 if (ERR==::slk_set(K.num,bf?K.label:"",K.format))