libyui-ncurses
2.44.1
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: NCurses.h 00020 00021 Author: Michael Andres <ma@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef NCurses_h 00026 #define NCurses_h 00027 00028 #include <iostream> 00029 #include <string> 00030 #include <set> 00031 #include <map> 00032 00033 #include <yui/YEvent.h> 00034 #include <yui/YWidget.h> 00035 #include <yui/YMenuItem.h> 00036 00037 #include <ncursesw/curses.h> /* curses.h: #define NCURSES_CH_T cchar_t */ 00038 #include <wchar.h> 00039 00040 #include "ncursesw.h" 00041 #include "ncursesp.h" 00042 #include "position.h" 00043 #include "NCstyle.h" 00044 00045 class NCWidget; 00046 class NCDialog; 00047 00048 00049 class NCursesError 00050 { 00051 public: 00052 00053 int errval_i; 00054 std::string errmsg_t; 00055 00056 NCursesError( const char * msg = "unknown error", ... ); 00057 NCursesError( int val, const char * msg = "unknown error", ... ); 00058 00059 virtual ~NCursesError() {} 00060 00061 NCursesError & NCError( const char * msg = "unknown error", ... ); 00062 NCursesError & NCError( int val, const char * msg = "unknown error", ... ); 00063 00064 virtual const char * location() const { return "NCurses"; } 00065 }; 00066 00067 extern std::ostream & operator<<( std::ostream & STREAM, const NCursesError & OBJ ); 00068 00069 00070 00071 class NCursesEvent 00072 { 00073 00074 public: 00075 00076 enum Type 00077 { 00078 handled = -1, 00079 none = 0, 00080 cancel, 00081 timeout, 00082 button, 00083 menu, 00084 key 00085 }; 00086 00087 enum DETAIL 00088 { 00089 NODETAIL = -1, 00090 CONTINUE = -2, 00091 USERDEF = -3 00092 }; 00093 00094 Type type; 00095 NCWidget * widget; 00096 YMenuItem * selection; // used for MenuEvent (the menu selection) 00097 00098 std::string result; // can be used for any (std::string) result 00099 00100 std::string keySymbol; // used for KeyEvent (symbol pressed key) 00101 00102 int detail; 00103 00104 YEvent::EventReason reason; 00105 00106 NCursesEvent( Type t = none, YEvent::EventReason r = YEvent::UnknownReason ) 00107 : type( t ) 00108 , widget( 0 ) 00109 , selection( 0 ) 00110 , result( "" ) 00111 , detail( NODETAIL ) 00112 , reason( r ) 00113 {} 00114 00115 virtual ~NCursesEvent() {} 00116 00117 // not operator bool() which would be propagated to almost everything 00118 operator void*() const { return type != none ? ( void* )1 : ( void* )0; } 00119 00120 bool operator==( const NCursesEvent & e ) const { return type == e.type; } 00121 00122 bool operator!=( const NCursesEvent & e ) const { return type != e.type; } 00123 00124 bool isReturnEvent() const { return type > none; } 00125 00126 bool isInternalEvent() const { return type < none; } 00127 00128 00129 // Some predefined events that can be used as return values 00130 00131 static const NCursesEvent Activated; 00132 static const NCursesEvent SelectionChanged; 00133 static const NCursesEvent ValueChanged; 00134 }; 00135 00136 extern std::ostream & operator<<( std::ostream & STREAM, const NCursesEvent & OBJ ); 00137 00138 00139 00140 class NCurses 00141 { 00142 00143 friend std::ostream & operator<<( std::ostream & STREAM, const NCurses & OBJ ); 00144 00145 NCurses & operator=( const NCurses & ); 00146 NCurses( const NCurses & ); 00147 00148 private: 00149 00150 static NCurses * myself; 00151 00152 static WINDOW * ripped_w_top; 00153 static WINDOW * ripped_w_bottom; 00154 static int ripinit_top( WINDOW * , int ); 00155 static int ripinit_bottom( WINDOW * , int ); 00156 00157 protected: 00158 00159 SCREEN * theTerm; 00160 std::string myTerm; 00161 std::string envTerm; 00162 WINDOW * title_w; 00163 WINDOW * status_w; 00164 std::string title_t; 00165 00166 std::map <int, std::string> status_line; 00167 00168 NCstyle * styleset; 00169 NCursesPanel * stdpan; 00170 00171 void init(); 00172 bool initialized() const { return stdpan; } 00173 00174 virtual bool title_line() { return true; } 00175 00176 virtual bool want_colors() { return true; } 00177 00178 virtual void setup_screen(); 00179 virtual void init_title(); 00180 virtual void init_screen(); 00181 00182 public: 00183 00184 NCurses(); 00185 virtual ~NCurses(); 00186 00187 int stdout_save; 00188 int stderr_save; 00189 00190 static int cols() { return ::COLS; } 00191 00192 static int lines() { return ::LINES; } 00193 00194 static int tabsize() { return ::TABSIZE; } 00195 00196 void run(); 00197 00198 public: 00199 00200 static const NCstyle & style(); 00201 00202 static void Update(); 00203 static void Redraw(); 00204 static void Refresh(); 00205 static void SetTitle( const std::string & str ); 00206 static void SetStatusLine( std::map <int, std::string> fkeys ); 00207 static void ScreenShot( const std::string & name = "screen.shot" ); 00208 00209 static void drawTitle(); 00210 00211 public: 00212 // actually not for public use 00213 static void ForgetDlg( NCDialog * dlg_r ); 00214 static void RememberDlg( NCDialog * dlg_r ); 00215 void RedirectToLog(); 00216 static void ResizeEvent(); 00217 00218 private: 00219 static std::set<NCDialog*> _knownDlgs; 00220 }; 00221 00222 00223 #define CTRL(x) ((x) & 0x1f) 00224 #define KEY_TAB 011 00225 #define KEY_RETURN 012 00226 #define KEY_ESC 033 00227 #define KEY_SPACE 040 00228 #define KEY_HOTKEY KEY_MAX+1 00229 00230 00231 #endif // NCurses_h