libyui-ncurses
Loading...
Searching...
No Matches
NCurses.h
1/*
2 Copyright (C) 2000-2012 Novell, Inc
3 This library is free software; you can redistribute it and/or modify
4 it under the terms of the GNU Lesser General Public License as
5 published by the Free Software Foundation; either version 2.1 of the
6 License, or (at your option) version 3.0 of the License. This library
7 is distributed in the hope that it will be useful, but WITHOUT ANY
8 WARRANTY; without even the implied warranty of MERCHANTABILITY or
9 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10 License for more details. You should have received a copy of the GNU
11 Lesser General Public License along with this library; if not, write
12 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13 Floor, Boston, MA 02110-1301 USA
14*/
15
16
17/*-/
18
19 File: NCurses.h
20
21 Author: Michael Andres <ma@suse.de>
22
23/-*/
24
25#ifndef NCurses_h
26#define NCurses_h
27
28#include <iostream>
29#include <string>
30#include <set>
31#include <map>
32
33#include <yui/YEvent.h>
34#include <yui/YWidget.h>
35#include <yui/YMenuItem.h>
36
37#include <ncursesw/curses.h> /* curses.h: #define NCURSES_CH_T cchar_t */
38#include <wchar.h>
39
40#include "ncursesw.h"
41#include "ncursesp.h"
42#include "position.h"
43#include "NCstyle.h"
44#include "NCstring.h"
45
46class NCWidget;
47class NCDialog;
48
49
51{
52public:
53
54 int errval_i;
55 std::string errmsg_t;
56
57 NCursesError( const char * msg = "unknown error", ... );
58 NCursesError( int val, const char * msg = "unknown error", ... );
59
60 virtual ~NCursesError() {}
61
62 NCursesError & NCError( const char * msg = "unknown error", ... );
63 NCursesError & NCError( int val, const char * msg = "unknown error", ... );
64
65 virtual const char * location() const { return "NCurses"; }
66};
67
68extern std::ostream & operator<<( std::ostream & str, const NCursesError & obj );
69
70
71
73{
74
75public:
76
77 enum Type
78 {
79 handled = -1,
80 none = 0,
81 cancel,
82 timeout,
83 button,
84 menu,
85 key,
86 debug,
87 special_key_config
88 };
89
90 enum DETAIL
91 {
92 NODETAIL = -1,
93 CONTINUE = -2,
94 USERDEF = -3
95 };
96
97 Type type;
98 NCWidget * widget;
99 YMenuItem * selection; // used for MenuEvent (the menu selection)
100
101 std::string result; // can be used for any (std::string) result
102
103 std::string keySymbol; // used for KeyEvent (symbol pressed key)
104
105 int detail;
106
107 YEvent::EventReason reason;
108
109 NCursesEvent( Type t = none, YEvent::EventReason r = YEvent::UnknownReason )
110 : type( t )
111 , widget( 0 )
112 , selection( 0 )
113 , result( "" )
114 , detail( NODETAIL )
115 , reason( r )
116 {}
117
118 virtual ~NCursesEvent() {}
119
120 // not operator bool() which would be propagated to almost everything
121 operator void*() const { return type != none ? ( void* )1 : ( void* )0; }
122
123 bool operator==( const NCursesEvent & e ) const { return type == e.type; }
124
125 bool operator!=( const NCursesEvent & e ) const { return type != e.type; }
126
127 bool isReturnEvent() const { return type > none; }
128
129 bool isInternalEvent() const { return type < none; }
130
131
132 // Some predefined events that can be used as return values
133
134 static const NCursesEvent Activated;
135 static const NCursesEvent SelectionChanged;
136 static const NCursesEvent ValueChanged;
137};
138
139extern std::ostream & operator<<( std::ostream & str, const NCursesEvent & obj );
140
141
142
144{
145
146 friend std::ostream & operator<<( std::ostream & str, const NCurses & obj );
147
148 NCurses & operator=( const NCurses & );
149 NCurses( const NCurses & );
150
151private:
152
153 static NCurses * myself;
154
155 static WINDOW * ripped_w_top;
156 static WINDOW * ripped_w_bottom;
157 static int ripinit_top( WINDOW * , int );
158 static int ripinit_bottom( WINDOW * , int );
159
160protected:
161
162 SCREEN * theTerm;
163 std::string myTerm;
164 std::string envTerm;
165 WINDOW * title_w;
166 WINDOW * status_w;
167 std::string title_t;
168
169 std::map <int, NCstring> status_line;
170
171 NCstyle * styleset;
172 NCursesPanel * stdpan;
173
174 void init();
175 bool initialized() const { return stdpan; }
176
177 virtual bool title_line() { return true; }
178
179 virtual bool want_colors() { return true; }
180
181 virtual void setup_screen();
182 virtual void init_title();
183 virtual void init_screen();
184
185public:
186
187 NCurses();
188 virtual ~NCurses();
189
190 int stdout_save;
191 int stderr_save;
192
193 static int cols() { return ::COLS; }
194
195 static int lines() { return ::LINES; }
196
197 static int tabsize() { return ::TABSIZE; }
198
199 void run();
200
201public:
202
203 static const NCstyle & style();
204
205 static void Update();
206 static void Redraw();
207 static void Refresh();
208 static void SetTitle( const std::string & str );
209 static void SetStatusLine( std::map <int, NCstring> fkeys );
210 static void ScreenShot( const std::string & name = "screen.shot" );
211
212 static void drawTitle();
213
214public:
215 // actually not for public use
216 static void ForgetDlg( NCDialog * dlg_r );
217 static void RememberDlg( NCDialog * dlg_r );
218 void RedirectToLog();
219 static void ResizeEvent();
220
221private:
222 static std::set<NCDialog*> _knownDlgs;
223};
224
225
226#define CTRL(x) ((x) & 0x1f)
227#define KEY_TAB 011
228#define KEY_RETURN 012
229#define KEY_ESC 033
230#define KEY_SPACE 040
231#define KEY_HOTKEY KEY_MAX+1
232
233
234#endif // NCurses_h
Definition NCDialog.h:40
Definition NCWidget.h:46
Definition NCstyle.h:233
Definition NCurses.h:51
Definition NCurses.h:73
Definition ncursesp.h:34
Definition NCurses.h:144