cursesapp.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // * This makes emacs happy -*-Mode: C++;-*-
  2. /****************************************************************************
  3. * Copyright (c) 1998-2005,2011 Free Software Foundation, Inc. *
  4. * *
  5. * Permission is hereby granted, free of charge, to any person obtaining a *
  6. * copy of this software and associated documentation files (the *
  7. * "Software"), to deal in the Software without restriction, including *
  8. * without limitation the rights to use, copy, modify, merge, publish, *
  9. * distribute, distribute with modifications, sublicense, and/or sell *
  10. * copies of the Software, and to permit persons to whom the Software is *
  11. * furnished to do so, subject to the following conditions: *
  12. * *
  13. * The above copyright notice and this permission notice shall be included *
  14. * in all copies or substantial portions of the Software. *
  15. * *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  17. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  19. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  22. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  23. * *
  24. * Except as contained in this notice, the name(s) of the above copyright *
  25. * holders shall not be used in advertising or otherwise to promote the *
  26. * sale, use or other dealings in this Software without prior written *
  27. * authorization. *
  28. ****************************************************************************/
  29. /****************************************************************************
  30. * Author: Juergen Pfeifer, 1997 *
  31. ****************************************************************************/
  32. // $Id: cursesapp.h,v 1.12 2011/09/17 22:12:10 tom Exp $
  33. #ifndef NCURSES_CURSESAPP_H_incl
  34. #define NCURSES_CURSESAPP_H_incl
  35. #include <cursslk.h>
  36. class NCURSES_IMPEXP NCursesApplication {
  37. public:
  38. typedef struct _slk_link { // This structure is used to maintain
  39. struct _slk_link* prev; // a stack of SLKs
  40. Soft_Label_Key_Set* SLKs;
  41. } SLK_Link;
  42. private:
  43. static int rinit(NCursesWindow& w); // Internal Init function for title
  44. static NCursesApplication* theApp; // Global ref. to the application
  45. static SLK_Link* slk_stack;
  46. protected:
  47. static NCursesWindow* titleWindow; // The Title Window (if any)
  48. bool b_Colors; // Is this a color application?
  49. NCursesWindow* Root_Window; // This is the stdscr equiv.
  50. // Initialization of attributes;
  51. // Rewrite this in your derived class if you prefer other settings
  52. virtual void init(bool bColors);
  53. // The number of lines for the title window. Default is no title window
  54. // You may rewrite this in your derived class
  55. virtual int titlesize() const {
  56. return 0;
  57. }
  58. // This method is called to put something into the title window initially
  59. // You may rewrite this in your derived class
  60. virtual void title() {
  61. }
  62. // The layout used for the Soft Label Keys. Default is to have no SLKs.
  63. // You may rewrite this in your derived class
  64. virtual Soft_Label_Key_Set::Label_Layout useSLKs() const {
  65. return Soft_Label_Key_Set::None;
  66. }
  67. // This method is called to initialize the SLKs. Default is nothing.
  68. // You may rewrite this in your derived class
  69. virtual void init_labels(Soft_Label_Key_Set& S) const {
  70. (void) S;
  71. }
  72. // Your derived class must implement this method. The return value must
  73. // be the exit value of your application.
  74. virtual int run() = 0;
  75. // The constructor is protected, so you may use it in your derived
  76. // class constructor. The argument tells whether or not you want colors.
  77. NCursesApplication(bool wantColors = FALSE);
  78. NCursesApplication& operator=(const NCursesApplication& rhs)
  79. {
  80. if (this != &rhs) {
  81. *this = rhs;
  82. }
  83. return *this;
  84. }
  85. NCursesApplication(const NCursesApplication& rhs)
  86. : b_Colors(rhs.b_Colors),
  87. Root_Window(rhs.Root_Window)
  88. {
  89. }
  90. public:
  91. virtual ~NCursesApplication();
  92. // Get a pointer to the current application object
  93. static NCursesApplication* getApplication() {
  94. return theApp;
  95. }
  96. // This method runs the application and returns its exit value
  97. int operator()(void);
  98. // Process the commandline arguments. The default implementation simply
  99. // ignores them. Your derived class may rewrite this.
  100. virtual void handleArgs(int argc, char* argv[]) {
  101. (void) argc;
  102. (void) argv;
  103. }
  104. // Does this application use colors?
  105. inline bool useColors() const {
  106. return b_Colors;
  107. }
  108. // Push the Key Set S onto the SLK Stack. S then becomes the current set
  109. // of Soft Labelled Keys.
  110. void push(Soft_Label_Key_Set& S);
  111. // Throw away the current set of SLKs and make the previous one the
  112. // new current set.
  113. bool pop();
  114. // Retrieve the current set of Soft Labelled Keys.
  115. Soft_Label_Key_Set* top() const;
  116. // Attributes to use for menu and forms foregrounds
  117. virtual chtype foregrounds() const {
  118. return b_Colors ? static_cast<chtype>(COLOR_PAIR(1)) : A_BOLD;
  119. }
  120. // Attributes to use for menu and forms backgrounds
  121. virtual chtype backgrounds() const {
  122. return b_Colors ? static_cast<chtype>(COLOR_PAIR(2)) : A_NORMAL;
  123. }
  124. // Attributes to use for inactive (menu) elements
  125. virtual chtype inactives() const {
  126. return b_Colors ? static_cast<chtype>(COLOR_PAIR(3)|A_DIM) : A_DIM;
  127. }
  128. // Attributes to use for (form) labels and SLKs
  129. virtual chtype labels() const {
  130. return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL;
  131. }
  132. // Attributes to use for form backgrounds
  133. virtual chtype dialog_backgrounds() const {
  134. return b_Colors ? static_cast<chtype>(COLOR_PAIR(4)) : A_NORMAL;
  135. }
  136. // Attributes to use as default for (form) window backgrounds
  137. virtual chtype window_backgrounds() const {
  138. return b_Colors ? static_cast<chtype>(COLOR_PAIR(5)) : A_NORMAL;
  139. }
  140. // Attributes to use for the title window
  141. virtual chtype screen_titles() const {
  142. return b_Colors ? static_cast<chtype>(COLOR_PAIR(6)) : A_BOLD;
  143. }
  144. };
  145. #endif /* NCURSES_CURSESAPP_H_incl */