X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=c%2B%2B%2Fcursslk.cc;h=9922163cd360692192e09dcf121f7ba9b852cf0a;hp=fbc5cda40b1f11578f0c1eea26e4358e528d327b;hb=a5fe3726f7d4374e9b1551b535c8617b423996f2;hpb=a8987e73ec254703634802b4f7ee30d3a485524d diff --git a/c++/cursslk.cc b/c++/cursslk.cc index fbc5cda4..9922163c 100644 --- a/c++/cursslk.cc +++ b/c++/cursslk.cc @@ -1,6 +1,7 @@ // * this is for making emacs happy: -*-Mode: C++;-*- /**************************************************************************** - * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. * + * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 1998-2005,2012 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -34,23 +35,27 @@ #include "internal.h" #include "cursslk.h" #include "cursesapp.h" -#include -MODULE_ID("$Id: cursslk.cc,v 1.11 2003/10/25 15:04:46 tom Exp $") +MODULE_ID("$Id: cursslk.cc,v 1.19 2020/07/18 19:57:11 anonymous.maarten Exp $") -void Soft_Label_Key_Set::Soft_Label_Key::operator=(char *text) { +Soft_Label_Key_Set::Soft_Label_Key& + Soft_Label_Key_Set::Soft_Label_Key::operator=(char *text) +{ delete[] label; - label = new char[1 + ::strlen(text)]; - (::strcpy)(label,text); + size_t need = 1 + ::strlen(text); + label = new char[need]; + ::_nc_STRCPY(label,text,need); + return *this; } long Soft_Label_Key_Set::count = 0L; int Soft_Label_Key_Set::num_labels = 0; -Soft_Label_Key_Set::Label_Layout +Soft_Label_Key_Set::Label_Layout Soft_Label_Key_Set::format = None; -void Soft_Label_Key_Set::init() { +void Soft_Label_Key_Set::init() +{ slk_array = new Soft_Label_Key[num_labels]; for(int i=0; i < num_labels; i++) { slk_array[i].num = i+1; @@ -58,18 +63,24 @@ void Soft_Label_Key_Set::init() { b_attrInit = FALSE; } -Soft_Label_Key_Set::Soft_Label_Key_Set() { +Soft_Label_Key_Set::Soft_Label_Key_Set() + : b_attrInit(FALSE), + slk_array(NULL) +{ if (format==None) Error("No default SLK layout"); init(); } -Soft_Label_Key_Set::Soft_Label_Key_Set(Soft_Label_Key_Set::Label_Layout fmt) { +Soft_Label_Key_Set::Soft_Label_Key_Set(Soft_Label_Key_Set::Label_Layout fmt) + : b_attrInit(FALSE), + slk_array(NULL) +{ if (fmt==None) Error("Invalid SLK Layout"); if (count++==0) { format = fmt; - if (ERR == ::slk_init((int)fmt)) + if (ERR == ::slk_init(static_cast(fmt))) Error("slk_init"); num_labels = (fmt>=PC_Style?12:8); } @@ -78,7 +89,7 @@ Soft_Label_Key_Set::Soft_Label_Key_Set(Soft_Label_Key_Set::Label_Layout fmt) { init(); } -Soft_Label_Key_Set::~Soft_Label_Key_Set() { +Soft_Label_Key_Set::~Soft_Label_Key_Set() THROWS(NCursesException) { if (!::isendwin()) clear(); delete[] slk_array; @@ -91,6 +102,10 @@ Soft_Label_Key_Set::Soft_Label_Key& Soft_Label_Key_Set::operator[](int i) { return slk_array[i-1]; } +int Soft_Label_Key_Set::labels() const { + return num_labels; +} + void Soft_Label_Key_Set::activate_label(int i, bool bf) { if (!b_attrInit) { NCursesApplication* A = NCursesApplication::getApplication(); @@ -103,7 +118,8 @@ void Soft_Label_Key_Set::activate_label(int i, bool bf) { noutrefresh(); } -void Soft_Label_Key_Set::activate_labels(bool bf) { +void Soft_Label_Key_Set::activate_labels(bool bf) +{ if (!b_attrInit) { NCursesApplication* A = NCursesApplication::getApplication(); if (A) attrset(A->labels());