cursslk.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // * this is for making emacs happy: -*-Mode: C++;-*-
  2. /****************************************************************************
  3. * Copyright 2019,2020 Thomas E. Dickey *
  4. * Copyright 1998-2003,2005 Free Software Foundation, Inc. *
  5. * *
  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: *
  13. * *
  14. * The above copyright notice and this permission notice shall be included *
  15. * in all copies or substantial portions of the Software. *
  16. * *
  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. *
  24. * *
  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 *
  28. * authorization. *
  29. ****************************************************************************/
  30. /****************************************************************************
  31. * Author: Juergen Pfeifer, 1997 *
  32. ****************************************************************************/
  33. // $Id: cursslk.h,v 1.15 2020/02/02 23:34:34 tom Exp $
  34. #ifndef NCURSES_CURSSLK_H_incl
  35. #define NCURSES_CURSSLK_H_incl
  36. #include <cursesw.h>
  37. class NCURSES_IMPEXP Soft_Label_Key_Set {
  38. public:
  39. // This inner class represents the attributes of a Soft Label Key (SLK)
  40. class NCURSES_IMPEXP Soft_Label_Key {
  41. friend class Soft_Label_Key_Set;
  42. public:
  43. typedef enum { Left=0, Center=1, Right=2 } Justification;
  44. private:
  45. char *label; // The Text of the Label
  46. Justification format; // The Justification
  47. int num; // The number of the Label
  48. Soft_Label_Key() : label(NULL), format(Left), num(-1) {
  49. }
  50. virtual ~Soft_Label_Key() {
  51. delete[] label;
  52. };
  53. public:
  54. // Set the text of the Label
  55. Soft_Label_Key& operator=(char *text);
  56. // Set the Justification of the Label
  57. Soft_Label_Key& operator=(Justification just) {
  58. format = just;
  59. return *this;
  60. }
  61. // Retrieve the text of the label
  62. inline char* operator()(void) const {
  63. return label;
  64. }
  65. Soft_Label_Key& operator=(const Soft_Label_Key& rhs)
  66. {
  67. if (this != &rhs) {
  68. *this = rhs;
  69. }
  70. return *this;
  71. }
  72. Soft_Label_Key(const Soft_Label_Key& rhs)
  73. : label(NULL),
  74. format(rhs.format),
  75. num(rhs.num)
  76. {
  77. *this = rhs.label;
  78. }
  79. };
  80. public:
  81. typedef enum {
  82. None = -1,
  83. Three_Two_Three = 0,
  84. Four_Four = 1,
  85. PC_Style = 2,
  86. PC_Style_With_Index = 3
  87. } Label_Layout;
  88. private:
  89. static long NCURSES_IMPEXP count; // Number of Key Sets
  90. static Label_Layout NCURSES_IMPEXP format; // Layout of the Key Sets
  91. static int NCURSES_IMPEXP num_labels; // Number Of Labels in Key Sets
  92. bool NCURSES_IMPEXP b_attrInit; // Are attributes initialized
  93. Soft_Label_Key *slk_array; // The array of SLK's
  94. // Init the Key Set
  95. void init();
  96. // Activate or Deactivate Label# i, Label counting starts with 1!
  97. void activate_label(int i, bool bf=TRUE);
  98. // Activate of Deactivate all Labels
  99. void activate_labels(bool bf);
  100. protected:
  101. inline void Error (const char* msg) const THROWS(NCursesException) {
  102. THROW(new NCursesException (msg));
  103. }
  104. // Remove SLK's from screen
  105. void clear() {
  106. if (ERR==::slk_clear())
  107. Error("slk_clear");
  108. }
  109. // Restore them
  110. void restore() {
  111. if (ERR==::slk_restore())
  112. Error("slk_restore");
  113. }
  114. public:
  115. // Construct a Key Set, use the most comfortable layout as default.
  116. // You must create a Soft_Label_Key_Set before you create any object of
  117. // the NCursesWindow, NCursesPanel or derived classes. (Actually before
  118. // ::initscr() is called).
  119. Soft_Label_Key_Set(Label_Layout fmt);
  120. // This constructor assumes, that you already constructed a Key Set
  121. // with a layout by the constructor above. This layout will be reused.
  122. NCURSES_IMPEXP Soft_Label_Key_Set();
  123. Soft_Label_Key_Set& operator=(const Soft_Label_Key_Set& rhs)
  124. {
  125. if (this != &rhs) {
  126. *this = rhs;
  127. init(); // allocate a new slk_array[]
  128. }
  129. return *this;
  130. }
  131. Soft_Label_Key_Set(const Soft_Label_Key_Set& rhs)
  132. : b_attrInit(rhs.b_attrInit),
  133. slk_array(NULL)
  134. {
  135. init(); // allocate a new slk_array[]
  136. }
  137. virtual ~Soft_Label_Key_Set() THROWS(NCursesException);
  138. // Get Label# i. Label counting starts with 1!
  139. NCURSES_IMPEXP Soft_Label_Key& operator[](int i);
  140. // Retrieve number of Labels
  141. inline int labels() const { return num_labels; }
  142. // Refresh the SLK portion of the screen
  143. inline void refresh() {
  144. if (ERR==::slk_refresh())
  145. Error("slk_refresh");
  146. }
  147. // Mark the SLK portion of the screen for refresh, defer actual refresh
  148. // until next update call.
  149. inline void noutrefresh() {
  150. if (ERR==::slk_noutrefresh())
  151. Error("slk_noutrefresh");
  152. }
  153. // Mark the whole SLK portion of the screen as modified
  154. inline void touch() {
  155. if (ERR==::slk_touch())
  156. Error("slk_touch");
  157. }
  158. // Activate Label# i
  159. inline void show(int i) {
  160. activate_label(i,FALSE);
  161. activate_label(i,TRUE);
  162. }
  163. // Hide Label# i
  164. inline void hide(int i) {
  165. activate_label(i,FALSE);
  166. }
  167. // Show all Labels
  168. inline void show() {
  169. activate_labels(FALSE);
  170. activate_labels(TRUE);
  171. }
  172. // Hide all Labels
  173. inline void hide() {
  174. activate_labels(FALSE);
  175. }
  176. inline void attron(attr_t attrs) {
  177. if (ERR==::slk_attron(attrs))
  178. Error("slk_attron");
  179. }
  180. inline void attroff(attr_t attrs) {
  181. if (ERR==::slk_attroff(attrs))
  182. Error("slk_attroff");
  183. }
  184. inline void attrset(attr_t attrs) {
  185. if (ERR==::slk_attrset(attrs))
  186. Error("slk_attrset");
  187. }
  188. inline void color(short color_pair_number) {
  189. if (ERR==::slk_color(color_pair_number))
  190. Error("slk_color");
  191. }
  192. inline attr_t attr() const {
  193. return ::slk_attr();
  194. }
  195. };
  196. #endif /* NCURSES_CURSSLK_H_incl */