cursesapp.h 7.1 KB

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