1 // * this is for making emacs happy: -*-Mode: C++;-*-
2 /****************************************************************************
3 * Copyright 2019-2020,2022 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.20 2022/02/26 17:57:23 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()
61 slk_array = new Soft_Label_Key[num_labels];
62 for(int i=0; i < num_labels; i++) {
63 slk_array[i].num = i+1;
68 Soft_Label_Key_Set::Soft_Label_Key_Set()
73 Error("No default SLK layout");
77 Soft_Label_Key_Set::Soft_Label_Key_Set(Soft_Label_Key_Set::Label_Layout fmt)
82 Error("Invalid SLK Layout");
85 if (ERR == ::slk_init(static_cast<int>(fmt)))
87 num_labels = (fmt>=PC_Style?12:8);
90 Error("All SLKs must have same layout");
94 Soft_Label_Key_Set::~Soft_Label_Key_Set() THROWS(NCursesException) {
101 Soft_Label_Key_Set::Soft_Label_Key& Soft_Label_Key_Set::operator[](int i) {
102 if (i<1 || i>num_labels)
103 Error("Invalid Label index");
104 return slk_array[i-1];
107 int Soft_Label_Key_Set::labels() const {
111 void Soft_Label_Key_Set::activate_label(int i, bool bf) {
113 NCursesApplication* A = NCursesApplication::getApplication();
114 if (A) attrset(A->labels());
117 Soft_Label_Key& K = (*this)[i];
118 if (ERR==::slk_set(K.num,bf?K.label:"",K.format))
123 void Soft_Label_Key_Set::activate_labels(bool bf)
126 NCursesApplication* A = NCursesApplication::getApplication();
127 if (A) attrset(A->labels());
130 for(int i=1; i <= num_labels; i++) {
131 Soft_Label_Key& K = (*this)[i];
132 if (ERR==::slk_set(K.num,bf?K.label:"",K.format))