Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:29:43

0001 // * this is for making emacs happy: -*-Mode: C++;-*-
0002 // vile:cppmode
0003 /****************************************************************************
0004  * Copyright 2019-2020,2021 Thomas E. Dickey                                *
0005  * Copyright 1998-2003,2005 Free Software Foundation, Inc.                  *
0006  *                                                                          *
0007  * Permission is hereby granted, free of charge, to any person obtaining a  *
0008  * copy of this software and associated documentation files (the            *
0009  * "Software"), to deal in the Software without restriction, including      *
0010  * without limitation the rights to use, copy, modify, merge, publish,      *
0011  * distribute, distribute with modifications, sublicense, and/or sell       *
0012  * copies of the Software, and to permit persons to whom the Software is    *
0013  * furnished to do so, subject to the following conditions:                 *
0014  *                                                                          *
0015  * The above copyright notice and this permission notice shall be included  *
0016  * in all copies or substantial portions of the Software.                   *
0017  *                                                                          *
0018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
0019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
0020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
0021  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
0022  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
0023  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
0024  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
0025  *                                                                          *
0026  * Except as contained in this notice, the name(s) of the above copyright   *
0027  * holders shall not be used in advertising or otherwise to promote the     *
0028  * sale, use or other dealings in this Software without prior written       *
0029  * authorization.                                                           *
0030  ****************************************************************************/
0031 
0032 /****************************************************************************
0033  *   Author: Juergen Pfeifer, 1997                                          *
0034  ****************************************************************************/
0035 
0036 // $Id: cursslk.h,v 1.19 2021/04/17 18:11:08 tom Exp $
0037 
0038 #ifndef NCURSES_CURSSLK_H_incl
0039 #define NCURSES_CURSSLK_H_incl
0040 
0041 #include <ncursesw/cursesw.h>
0042 
0043 class NCURSES_CXX_IMPEXP Soft_Label_Key_Set {
0044 public:
0045   // This inner class represents the attributes of a Soft Label Key (SLK)
0046   class NCURSES_CXX_IMPEXP Soft_Label_Key {
0047     friend class Soft_Label_Key_Set;
0048   public:
0049     typedef enum { Left=0, Center=1, Right=2 } Justification;
0050 
0051   private:
0052     char *label;           // The Text of the Label
0053     Justification format;  // The Justification
0054     int num;               // The number of the Label
0055 
0056     Soft_Label_Key() : label(NULL), format(Left), num(-1) {
0057     }
0058 
0059     virtual ~Soft_Label_Key() {
0060       delete[] label;
0061     };
0062 
0063   public:
0064     // Set the text of the Label
0065     Soft_Label_Key& operator=(char *text);
0066 
0067     // Set the Justification of the Label
0068     Soft_Label_Key& operator=(Justification just) {
0069       format = just;
0070       return *this;
0071     }
0072 
0073     // Retrieve the text of the label
0074     inline char* operator()(void) const {
0075       return label;
0076     }
0077 
0078     Soft_Label_Key& operator=(const Soft_Label_Key& rhs)
0079     {
0080       if (this != &rhs) {
0081         *this = rhs;
0082       }
0083       return *this;
0084     }
0085 
0086     Soft_Label_Key(const Soft_Label_Key& rhs)
0087       : label(NULL),
0088         format(rhs.format),
0089         num(rhs.num)
0090     {
0091       *this = rhs.label;
0092     }
0093   };
0094 
0095 public:
0096   typedef enum {
0097     None                = -1,
0098     Three_Two_Three     = 0,
0099     Four_Four           = 1,
0100     PC_Style            = 2,
0101     PC_Style_With_Index = 3
0102   } Label_Layout;
0103 
0104 private:
0105   static long count;               // Number of Key Sets
0106   static Label_Layout  format;     // Layout of the Key Sets
0107   static int  num_labels;          // Number Of Labels in Key Sets
0108   bool b_attrInit;                 // Are attributes initialized
0109 
0110   Soft_Label_Key *slk_array;       // The array of SLK's
0111 
0112   // Init the Key Set
0113   void init();
0114 
0115   // Activate or Deactivate Label# i, Label counting starts with 1!
0116   void activate_label(int i, bool bf=TRUE);
0117 
0118   // Activate of Deactivate all Labels
0119   void activate_labels(bool bf);
0120 
0121 protected:
0122   inline void Error (const char* msg) const THROWS(NCursesException) {
0123     THROW(new NCursesException (msg));
0124   }
0125 
0126   // Remove SLK's from screen
0127   void clear() {
0128     if (ERR==::slk_clear())
0129       Error("slk_clear");
0130   }
0131 
0132   // Restore them
0133   void restore() {
0134     if (ERR==::slk_restore())
0135       Error("slk_restore");
0136   }
0137 
0138 public:
0139 
0140   // Construct a Key Set, use the most comfortable layout as default.
0141   // You must create a Soft_Label_Key_Set before you create any object of
0142   // the NCursesWindow, NCursesPanel or derived classes. (Actually before
0143   // ::initscr() is called).
0144   explicit Soft_Label_Key_Set(Label_Layout fmt);
0145 
0146   // This constructor assumes, that you already constructed a Key Set
0147   // with a layout by the constructor above. This layout will be reused.
0148   Soft_Label_Key_Set();
0149 
0150   Soft_Label_Key_Set& operator=(const Soft_Label_Key_Set& rhs)
0151   {
0152     if (this != &rhs) {
0153       *this = rhs;
0154       init();       // allocate a new slk_array[]
0155     }
0156     return *this;
0157   }
0158 
0159   Soft_Label_Key_Set(const Soft_Label_Key_Set& rhs)
0160     : b_attrInit(rhs.b_attrInit),
0161       slk_array(NULL)
0162   {
0163     init();     // allocate a new slk_array[]
0164   }
0165 
0166   virtual ~Soft_Label_Key_Set() THROWS(NCursesException);
0167 
0168   // Get Label# i. Label counting starts with 1!
0169   Soft_Label_Key& operator[](int i);
0170 
0171   // Retrieve number of Labels
0172   int labels() const;
0173 
0174   // Refresh the SLK portion of the screen
0175   inline void refresh() {
0176     if (ERR==::slk_refresh())
0177       Error("slk_refresh");
0178   }
0179 
0180   // Mark the SLK portion of the screen for refresh, defer actual refresh
0181   // until next update call.
0182   inline void noutrefresh() {
0183     if (ERR==::slk_noutrefresh())
0184       Error("slk_noutrefresh");
0185   }
0186 
0187   // Mark the whole SLK portion of the screen as modified
0188   inline void touch() {
0189     if (ERR==::slk_touch())
0190       Error("slk_touch");
0191   }
0192 
0193   // Activate Label# i
0194   inline void show(int i) {
0195     activate_label(i,FALSE);
0196     activate_label(i,TRUE);
0197   }
0198 
0199   // Hide Label# i
0200   inline void hide(int i) {
0201     activate_label(i,FALSE);
0202   }
0203 
0204   // Show all Labels
0205   inline void show() {
0206     activate_labels(FALSE);
0207     activate_labels(TRUE);
0208   }
0209 
0210   // Hide all Labels
0211   inline void hide() {
0212     activate_labels(FALSE);
0213   }
0214 
0215   inline void attron(attr_t attrs) {
0216     if (ERR==::slk_attron(attrs))
0217       Error("slk_attron");
0218   }
0219 
0220   inline void attroff(attr_t attrs) {
0221     if (ERR==::slk_attroff(attrs))
0222       Error("slk_attroff");
0223   }
0224 
0225   inline void attrset(attr_t attrs) {
0226     if (ERR==::slk_attrset(attrs))
0227       Error("slk_attrset");
0228   }
0229 
0230   inline void color(short color_pair_number) {
0231     if (ERR==::slk_color(color_pair_number))
0232       Error("slk_color");
0233   }
0234 
0235   inline attr_t attr() const {
0236     return ::slk_attr();
0237   }
0238 };
0239 
0240 #endif /* NCURSES_CURSSLK_H_incl */