jpayne@69: // * this is for making emacs happy: -*-Mode: C++;-*- jpayne@69: // vile:cppmode jpayne@69: /**************************************************************************** jpayne@69: * Copyright 2019-2020,2021 Thomas E. Dickey * jpayne@69: * Copyright 1998-2003,2005 Free Software Foundation, Inc. * jpayne@69: * * jpayne@69: * Permission is hereby granted, free of charge, to any person obtaining a * jpayne@69: * copy of this software and associated documentation files (the * jpayne@69: * "Software"), to deal in the Software without restriction, including * jpayne@69: * without limitation the rights to use, copy, modify, merge, publish, * jpayne@69: * distribute, distribute with modifications, sublicense, and/or sell * jpayne@69: * copies of the Software, and to permit persons to whom the Software is * jpayne@69: * furnished to do so, subject to the following conditions: * jpayne@69: * * jpayne@69: * The above copyright notice and this permission notice shall be included * jpayne@69: * in all copies or substantial portions of the Software. * jpayne@69: * * jpayne@69: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * jpayne@69: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * jpayne@69: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * jpayne@69: * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * jpayne@69: * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * jpayne@69: * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * jpayne@69: * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * jpayne@69: * * jpayne@69: * Except as contained in this notice, the name(s) of the above copyright * jpayne@69: * holders shall not be used in advertising or otherwise to promote the * jpayne@69: * sale, use or other dealings in this Software without prior written * jpayne@69: * authorization. * jpayne@69: ****************************************************************************/ jpayne@69: jpayne@69: /**************************************************************************** jpayne@69: * Author: Juergen Pfeifer, 1997 * jpayne@69: ****************************************************************************/ jpayne@69: jpayne@69: // $Id: cursslk.h,v 1.19 2021/04/17 18:11:08 tom Exp $ jpayne@69: jpayne@69: #ifndef NCURSES_CURSSLK_H_incl jpayne@69: #define NCURSES_CURSSLK_H_incl jpayne@69: jpayne@69: #include jpayne@69: jpayne@69: class NCURSES_CXX_IMPEXP Soft_Label_Key_Set { jpayne@69: public: jpayne@69: // This inner class represents the attributes of a Soft Label Key (SLK) jpayne@69: class NCURSES_CXX_IMPEXP Soft_Label_Key { jpayne@69: friend class Soft_Label_Key_Set; jpayne@69: public: jpayne@69: typedef enum { Left=0, Center=1, Right=2 } Justification; jpayne@69: jpayne@69: private: jpayne@69: char *label; // The Text of the Label jpayne@69: Justification format; // The Justification jpayne@69: int num; // The number of the Label jpayne@69: jpayne@69: Soft_Label_Key() : label(NULL), format(Left), num(-1) { jpayne@69: } jpayne@69: jpayne@69: virtual ~Soft_Label_Key() { jpayne@69: delete[] label; jpayne@69: }; jpayne@69: jpayne@69: public: jpayne@69: // Set the text of the Label jpayne@69: Soft_Label_Key& operator=(char *text); jpayne@69: jpayne@69: // Set the Justification of the Label jpayne@69: Soft_Label_Key& operator=(Justification just) { jpayne@69: format = just; jpayne@69: return *this; jpayne@69: } jpayne@69: jpayne@69: // Retrieve the text of the label jpayne@69: inline char* operator()(void) const { jpayne@69: return label; jpayne@69: } jpayne@69: jpayne@69: Soft_Label_Key& operator=(const Soft_Label_Key& rhs) jpayne@69: { jpayne@69: if (this != &rhs) { jpayne@69: *this = rhs; jpayne@69: } jpayne@69: return *this; jpayne@69: } jpayne@69: jpayne@69: Soft_Label_Key(const Soft_Label_Key& rhs) jpayne@69: : label(NULL), jpayne@69: format(rhs.format), jpayne@69: num(rhs.num) jpayne@69: { jpayne@69: *this = rhs.label; jpayne@69: } jpayne@69: }; jpayne@69: jpayne@69: public: jpayne@69: typedef enum { jpayne@69: None = -1, jpayne@69: Three_Two_Three = 0, jpayne@69: Four_Four = 1, jpayne@69: PC_Style = 2, jpayne@69: PC_Style_With_Index = 3 jpayne@69: } Label_Layout; jpayne@69: jpayne@69: private: jpayne@69: static long count; // Number of Key Sets jpayne@69: static Label_Layout format; // Layout of the Key Sets jpayne@69: static int num_labels; // Number Of Labels in Key Sets jpayne@69: bool b_attrInit; // Are attributes initialized jpayne@69: jpayne@69: Soft_Label_Key *slk_array; // The array of SLK's jpayne@69: jpayne@69: // Init the Key Set jpayne@69: void init(); jpayne@69: jpayne@69: // Activate or Deactivate Label# i, Label counting starts with 1! jpayne@69: void activate_label(int i, bool bf=TRUE); jpayne@69: jpayne@69: // Activate of Deactivate all Labels jpayne@69: void activate_labels(bool bf); jpayne@69: jpayne@69: protected: jpayne@69: inline void Error (const char* msg) const THROWS(NCursesException) { jpayne@69: THROW(new NCursesException (msg)); jpayne@69: } jpayne@69: jpayne@69: // Remove SLK's from screen jpayne@69: void clear() { jpayne@69: if (ERR==::slk_clear()) jpayne@69: Error("slk_clear"); jpayne@69: } jpayne@69: jpayne@69: // Restore them jpayne@69: void restore() { jpayne@69: if (ERR==::slk_restore()) jpayne@69: Error("slk_restore"); jpayne@69: } jpayne@69: jpayne@69: public: jpayne@69: jpayne@69: // Construct a Key Set, use the most comfortable layout as default. jpayne@69: // You must create a Soft_Label_Key_Set before you create any object of jpayne@69: // the NCursesWindow, NCursesPanel or derived classes. (Actually before jpayne@69: // ::initscr() is called). jpayne@69: explicit Soft_Label_Key_Set(Label_Layout fmt); jpayne@69: jpayne@69: // This constructor assumes, that you already constructed a Key Set jpayne@69: // with a layout by the constructor above. This layout will be reused. jpayne@69: Soft_Label_Key_Set(); jpayne@69: jpayne@69: Soft_Label_Key_Set& operator=(const Soft_Label_Key_Set& rhs) jpayne@69: { jpayne@69: if (this != &rhs) { jpayne@69: *this = rhs; jpayne@69: init(); // allocate a new slk_array[] jpayne@69: } jpayne@69: return *this; jpayne@69: } jpayne@69: jpayne@69: Soft_Label_Key_Set(const Soft_Label_Key_Set& rhs) jpayne@69: : b_attrInit(rhs.b_attrInit), jpayne@69: slk_array(NULL) jpayne@69: { jpayne@69: init(); // allocate a new slk_array[] jpayne@69: } jpayne@69: jpayne@69: virtual ~Soft_Label_Key_Set() THROWS(NCursesException); jpayne@69: jpayne@69: // Get Label# i. Label counting starts with 1! jpayne@69: Soft_Label_Key& operator[](int i); jpayne@69: jpayne@69: // Retrieve number of Labels jpayne@69: int labels() const; jpayne@69: jpayne@69: // Refresh the SLK portion of the screen jpayne@69: inline void refresh() { jpayne@69: if (ERR==::slk_refresh()) jpayne@69: Error("slk_refresh"); jpayne@69: } jpayne@69: jpayne@69: // Mark the SLK portion of the screen for refresh, defer actual refresh jpayne@69: // until next update call. jpayne@69: inline void noutrefresh() { jpayne@69: if (ERR==::slk_noutrefresh()) jpayne@69: Error("slk_noutrefresh"); jpayne@69: } jpayne@69: jpayne@69: // Mark the whole SLK portion of the screen as modified jpayne@69: inline void touch() { jpayne@69: if (ERR==::slk_touch()) jpayne@69: Error("slk_touch"); jpayne@69: } jpayne@69: jpayne@69: // Activate Label# i jpayne@69: inline void show(int i) { jpayne@69: activate_label(i,FALSE); jpayne@69: activate_label(i,TRUE); jpayne@69: } jpayne@69: jpayne@69: // Hide Label# i jpayne@69: inline void hide(int i) { jpayne@69: activate_label(i,FALSE); jpayne@69: } jpayne@69: jpayne@69: // Show all Labels jpayne@69: inline void show() { jpayne@69: activate_labels(FALSE); jpayne@69: activate_labels(TRUE); jpayne@69: } jpayne@69: jpayne@69: // Hide all Labels jpayne@69: inline void hide() { jpayne@69: activate_labels(FALSE); jpayne@69: } jpayne@69: jpayne@69: inline void attron(attr_t attrs) { jpayne@69: if (ERR==::slk_attron(attrs)) jpayne@69: Error("slk_attron"); jpayne@69: } jpayne@69: jpayne@69: inline void attroff(attr_t attrs) { jpayne@69: if (ERR==::slk_attroff(attrs)) jpayne@69: Error("slk_attroff"); jpayne@69: } jpayne@69: jpayne@69: inline void attrset(attr_t attrs) { jpayne@69: if (ERR==::slk_attrset(attrs)) jpayne@69: Error("slk_attrset"); jpayne@69: } jpayne@69: jpayne@69: inline void color(short color_pair_number) { jpayne@69: if (ERR==::slk_color(color_pair_number)) jpayne@69: Error("slk_color"); jpayne@69: } jpayne@69: jpayne@69: inline attr_t attr() const { jpayne@69: return ::slk_attr(); jpayne@69: } jpayne@69: }; jpayne@69: jpayne@69: #endif /* NCURSES_CURSSLK_H_incl */