cursesapp.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. // * This makes emacs happy -*-Mode: C++;-*-
  2. /****************************************************************************
  3. * Copyright 2019,2020 Thomas E. Dickey *
  4. * Copyright 1998-2005,2011 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: cursesapp.h,v 1.14 2020/02/02 23:34:34 tom Exp $
  34. #ifndef NCURSES_CURSESAPP_H_incl
  35. #define NCURSES_CURSESAPP_H_incl
  36. #include <cursslk.h>
  37. class NCURSES_IMPEXP NCursesApplication {
  38. public:
  39. typedef struct _slk_link { // This structure is used to maintain
  40. struct _slk_link* prev; // a stack of SLKs
  41. Soft_Label_Key_Set* SLKs;
  42. } SLK_Link;
  43. private:
  44. static int rinit(NCursesWindow& w); // Internal Init function for title
  45. static NCursesApplication* theApp; // Global ref. to the application
  46. static SLK_Link* slk_stack;
  47. protected:
  48. static NCursesWindow* titleWindow; // The Title Window (if any)
  49. bool b_Colors; // Is this a color application?
  50. NCursesWindow* Root_Window; // This is the stdscr equiv.
  51. // Initialization of attributes;
  52. // Rewrite this in your derived class if you prefer other settings
  53. virtual void init(bool bColors);
  54. // The number of lines for the title window. Default is no title window
  55. // You may rewrite this in your derived class
  56. virtual int titlesize() const {
  57. return 0;
  58. }
  59. // This method is called to put something into the title window initially
  60. // You may rewrite this in your derived class
  61. virtual void title() {
  62. }
  63. // The layout used for the Soft Label Keys. Default is to have no SLKs.
  64. // You may rewrite this in your derived class
  65. virtual Soft_Label_Key_Set::Label_Layout useSLKs() const {
  66. return Soft_Label_Key_Set::None;
  67. }
  68. // This method is called to initialize the SLKs. Default is nothing.
  69. // You may rewrite this in your derived class
  70. virtual void init_labels(Soft_Label_Key_Set& S) const {
  71. (void) S;
  72. }
  73. // Your derived class must implement this method. The return value must
  74. // be the exit value of your application.
  75. virtual int run() = 0;
  76. // The constructor is protected, so you may use it in your derived
  77. // class constructor. The argument tells whether or not you want colors.
  78. NCursesApplication(bool wantColors = FALSE);
  79. NCursesApplication& operator=(const NCursesApplication& rhs)
  80. {
  81. if (this != &rhs) {
  82. *this = rhs;
  83. }
  84. return *this;
  85. }
  86. NCursesApplication(const NCursesApplication& rhs)
  87. : b_Colors(rhs.b_Colors),
  88. Root_Window(rhs.Root_Window)
  89. {
  90. }
  91. public:
  92. virtual ~NCursesApplication() THROWS(NCursesException);
  93. // Get a pointer to the current application object
  94. static NCursesApplication* getApplication() {
  95. return theApp;
  96. }
  97. // This method runs the application and returns its exit value
  98. int operator()(void);
  99. // Process the commandline arguments. The default implementation simply
  100. // ignores them. Your derived class may rewrite this.
  101. virtual void handleArgs(int argc, char* argv[]) {
  102. (void) argc;
  103. (void) argv;
  104. }
  105. // Does this application use colors?
  106. inline bool useColors() const {
  107. return b_Colors;
  108. }
  109. // Push the Key Set S onto the SLK Stack. S then becomes the current set
  110. // of Soft Labelled Keys.
  111. void push(Soft_Label_Key_Set& S);
  112. // Throw away the current set of SLKs and make the previous one the
  113. // new current set.
  114. bool pop();
  115. // Retrieve the current set of Soft Labelled Keys.
  116. Soft_Label_Key_Set* top() const;
  117. // Attributes to use for menu and forms foregrounds
  118. virtual chtype foregrounds() const {
  119. return b_Colors ? static_cast<chtype>(COLOR_PAIR(1)) : A_BOLD;
  120. }
  121. // Attributes to use for menu and forms backgrounds
  122. virtual chtype backgrounds() const {
  123. return b_Colors ? static_cast<chtype>(COLOR_PAIR(2)) : A_NORMAL;
  124. }
  125. // Attributes to use for inactive (menu) elements
  126. virtual chtype inactives() const {
  127. return b_Colors ? static_cast<chtype>(COLOR_PAIR(3)|A_DIM) : A_DIM;
  128. }
  129. // Attributes to use for (form) labels and SLKs
  130. virtual chtype labels() const {
  131. return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL;
  132. }
  133. // Attributes to use for form backgrounds
  134. virtual chtype dialog_backgrounds() const {
  135. return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL;
  136. }
  137. // Attributes to use as default for (form) window backgrounds
  138. virtual chtype window_backgrounds() const {
  139. return b_Colors ? static_cast<chtype>(COLOR_PAIR(5)) : A_NORMAL;
  140. }
  141. // Attributes to use for the title window
  142. virtual chtype screen_titles() const {
  143. return b_Colors ? static_cast<chtype>(COLOR_PAIR(6)) : A_BOLD;
  144. }
  145. };
  146. #endif /* NCURSES_CURSESAPP_H_incl */