cursslk.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. // * this is for making emacs happy: -*-Mode: C++;-*-
  2. // vile:cppmode
  3. /****************************************************************************
  4. * Copyright 2019-2020,2021 Thomas E. Dickey *
  5. * Copyright 1998-2003,2005 Free Software Foundation, Inc. *
  6. * *
  7. * Permission is hereby granted, free of charge, to any person obtaining a *
  8. * copy of this software and associated documentation files (the *
  9. * "Software"), to deal in the Software without restriction, including *
  10. * without limitation the rights to use, copy, modify, merge, publish, *
  11. * distribute, distribute with modifications, sublicense, and/or sell *
  12. * copies of the Software, and to permit persons to whom the Software is *
  13. * furnished to do so, subject to the following conditions: *
  14. * *
  15. * The above copyright notice and this permission notice shall be included *
  16. * in all copies or substantial portions of the Software. *
  17. * *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  21. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  22. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  23. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  24. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  25. * *
  26. * Except as contained in this notice, the name(s) of the above copyright *
  27. * holders shall not be used in advertising or otherwise to promote the *
  28. * sale, use or other dealings in this Software without prior written *
  29. * authorization. *
  30. ****************************************************************************/
  31. /****************************************************************************
  32. * Author: Juergen Pfeifer, 1997 *
  33. ****************************************************************************/
  34. // $Id: cursslk.h,v 1.19 2021/04/17 18:11:08 tom Exp $
  35. #ifndef NCURSES_CURSSLK_H_incl
  36. #define NCURSES_CURSSLK_H_incl
  37. #include <ncursesw/cursesw.h>
  38. class NCURSES_CXX_IMPEXP Soft_Label_Key_Set {
  39. public:
  40. // This inner class represents the attributes of a Soft Label Key (SLK)
  41. class NCURSES_CXX_IMPEXP Soft_Label_Key {
  42. friend class Soft_Label_Key_Set;
  43. public:
  44. typedef enum { Left=0, Center=1, Right=2 } Justification;
  45. private:
  46. char *label; // The Text of the Label
  47. Justification format; // The Justification
  48. int num; // The number of the Label
  49. Soft_Label_Key() : label(NULL), format(Left), num(-1) {
  50. }
  51. virtual ~Soft_Label_Key() {
  52. delete[] label;
  53. };
  54. public:
  55. // Set the text of the Label
  56. Soft_Label_Key& operator=(char *text);
  57. // Set the Justification of the Label
  58. Soft_Label_Key& operator=(Justification just) {
  59. format = just;
  60. return *this;
  61. }
  62. // Retrieve the text of the label
  63. inline char* operator()(void) const {
  64. return label;
  65. }
  66. Soft_Label_Key& operator=(const Soft_Label_Key& rhs)
  67. {
  68. if (this != &rhs) {
  69. *this = rhs;
  70. }
  71. return *this;
  72. }
  73. Soft_Label_Key(const Soft_Label_Key& rhs)
  74. : label(NULL),
  75. format(rhs.format),
  76. num(rhs.num)
  77. {
  78. *this = rhs.label;
  79. }
  80. };
  81. public:
  82. typedef enum {
  83. None = -1,
  84. Three_Two_Three = 0,
  85. Four_Four = 1,
  86. PC_Style = 2,
  87. PC_Style_With_Index = 3
  88. } Label_Layout;
  89. private:
  90. static long count; // Number of Key Sets
  91. static Label_Layout format; // Layout of the Key Sets
  92. static int num_labels; // Number Of Labels in Key Sets
  93. bool b_attrInit; // Are attributes initialized
  94. Soft_Label_Key *slk_array; // The array of SLK's
  95. // Init the Key Set
  96. void init();
  97. // Activate or Deactivate Label# i, Label counting starts with 1!
  98. void activate_label(int i, bool bf=TRUE);
  99. // Activate of Deactivate all Labels
  100. void activate_labels(bool bf);
  101. protected:
  102. inline void Error (const char* msg) const THROWS(NCursesException) {
  103. THROW(new NCursesException (msg));
  104. }
  105. // Remove SLK's from screen
  106. void clear() {
  107. if (ERR==::slk_clear())
  108. Error("slk_clear");
  109. }
  110. // Restore them
  111. void restore() {
  112. if (ERR==::slk_restore())
  113. Error("slk_restore");
  114. }
  115. public:
  116. // Construct a Key Set, use the most comfortable layout as default.
  117. // You must create a Soft_Label_Key_Set before you create any object of
  118. // the NCursesWindow, NCursesPanel or derived classes. (Actually before
  119. // ::initscr() is called).
  120. explicit Soft_Label_Key_Set(Label_Layout fmt);
  121. // This constructor assumes, that you already constructed a Key Set
  122. // with a layout by the constructor above. This layout will be reused.
  123. Soft_Label_Key_Set();
  124. Soft_Label_Key_Set& operator=(const Soft_Label_Key_Set& rhs)
  125. {
  126. if (this != &rhs) {
  127. *this = rhs;
  128. init(); // allocate a new slk_array[]
  129. }
  130. return *this;
  131. }
  132. Soft_Label_Key_Set(const Soft_Label_Key_Set& rhs)
  133. : b_attrInit(rhs.b_attrInit),
  134. slk_array(NULL)
  135. {
  136. init(); // allocate a new slk_array[]
  137. }
  138. virtual ~Soft_Label_Key_Set() THROWS(NCursesException);
  139. // Get Label# i. Label counting starts with 1!
  140. Soft_Label_Key& operator[](int i);
  141. // Retrieve number of Labels
  142. int labels() const;
  143. // Refresh the SLK portion of the screen
  144. inline void refresh() {
  145. if (ERR==::slk_refresh())
  146. Error("slk_refresh");
  147. }
  148. // Mark the SLK portion of the screen for refresh, defer actual refresh
  149. // until next update call.
  150. inline void noutrefresh() {
  151. if (ERR==::slk_noutrefresh())
  152. Error("slk_noutrefresh");
  153. }
  154. // Mark the whole SLK portion of the screen as modified
  155. inline void touch() {
  156. if (ERR==::slk_touch())
  157. Error("slk_touch");
  158. }
  159. // Activate Label# i
  160. inline void show(int i) {
  161. activate_label(i,FALSE);
  162. activate_label(i,TRUE);
  163. }
  164. // Hide Label# i
  165. inline void hide(int i) {
  166. activate_label(i,FALSE);
  167. }
  168. // Show all Labels
  169. inline void show() {
  170. activate_labels(FALSE);
  171. activate_labels(TRUE);
  172. }
  173. // Hide all Labels
  174. inline void hide() {
  175. activate_labels(FALSE);
  176. }
  177. inline void attron(attr_t attrs) {
  178. if (ERR==::slk_attron(attrs))
  179. Error("slk_attron");
  180. }
  181. inline void attroff(attr_t attrs) {
  182. if (ERR==::slk_attroff(attrs))
  183. Error("slk_attroff");
  184. }
  185. inline void attrset(attr_t attrs) {
  186. if (ERR==::slk_attrset(attrs))
  187. Error("slk_attrset");
  188. }
  189. inline void color(short color_pair_number) {
  190. if (ERR==::slk_color(color_pair_number))
  191. Error("slk_color");
  192. }
  193. inline attr_t attr() const {
  194. return ::slk_attr();
  195. }
  196. };
  197. #endif /* NCURSES_CURSSLK_H_incl */