cursesapp.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // * This makes emacs happy -*-Mode: C++;-*-
  2. /****************************************************************************
  3. * Copyright (c) 1998-2003,2005 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.11 2005/05/28 21:57:44 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. }
  71. // Your derived class must implement this method. The return value must
  72. // be the exit value of your application.
  73. virtual int run() = 0;
  74. // The constructor is protected, so you may use it in your derived
  75. // class constructor. The argument tells whether or not you want colors.
  76. NCursesApplication(bool wantColors = FALSE);
  77. NCursesApplication& operator=(const NCursesApplication& rhs)
  78. {
  79. if (this != &rhs) {
  80. *this = rhs;
  81. }
  82. return *this;
  83. }
  84. NCursesApplication(const NCursesApplication& rhs)
  85. : b_Colors(rhs.b_Colors),
  86. Root_Window(rhs.Root_Window)
  87. {
  88. }
  89. public:
  90. virtual ~NCursesApplication();
  91. // Get a pointer to the current application object
  92. static NCursesApplication* getApplication() {
  93. return theApp;
  94. }
  95. // This method runs the application and returns its exit value
  96. int operator()(void);
  97. // Process the commandline arguments. The default implementation simply
  98. // ignores them. Your derived class may rewrite this.
  99. virtual void handleArgs(int argc, char* argv[]) {
  100. }
  101. // Does this application use colors?
  102. inline bool useColors() const {
  103. return b_Colors;
  104. }
  105. // Push the Key Set S onto the SLK Stack. S then becomes the current set
  106. // of Soft Labelled Keys.
  107. void push(Soft_Label_Key_Set& S);
  108. // Throw away the current set of SLKs and make the previous one the
  109. // new current set.
  110. bool pop();
  111. // Retrieve the current set of Soft Labelled Keys.
  112. Soft_Label_Key_Set* top() const;
  113. // Attributes to use for menu and forms foregrounds
  114. virtual chtype foregrounds() const {
  115. return b_Colors ? COLOR_PAIR(1) : A_BOLD;
  116. }
  117. // Attributes to use for menu and forms backgrounds
  118. virtual chtype backgrounds() const {
  119. return b_Colors ? COLOR_PAIR(2) : A_NORMAL;
  120. }
  121. // Attributes to use for inactive (menu) elements
  122. virtual chtype inactives() const {
  123. return b_Colors ? (COLOR_PAIR(3)|A_DIM) : A_DIM;
  124. }
  125. // Attributes to use for (form) labels and SLKs
  126. virtual chtype labels() const {
  127. return b_Colors ? COLOR_PAIR(4) : A_NORMAL;
  128. }
  129. // Attributes to use for form backgrounds
  130. virtual chtype dialog_backgrounds() const {
  131. return b_Colors ? COLOR_PAIR(4) : A_NORMAL;
  132. }
  133. // Attributes to use as default for (form) window backgrounds
  134. virtual chtype window_backgrounds() const {
  135. return b_Colors ? COLOR_PAIR(5) : A_NORMAL;
  136. }
  137. // Attributes to use for the title window
  138. virtual chtype screen_titles() const {
  139. return b_Colors ? COLOR_PAIR(6) : A_BOLD;
  140. }
  141. };
  142. #endif /* NCURSES_CURSESAPP_H_incl */