Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

NCurses.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                                                                      |
00003 |                      __   __    ____ _____ ____                      |
00004 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00005 |                       \ V / _` \___ \ | |   __) |                    |
00006 |                        | | (_| |___) || |  / __/                     |
00007 |                        |_|\__,_|____/ |_| |_____|                    |
00008 |                                                                      |
00009 |                               core system                            |
00010 |                                                        (C) SuSE GmbH |
00011 \----------------------------------------------------------------------/
00012 
00013    File:       NCurses.h
00014 
00015    Author:     Michael Andres <ma@suse.de>
00016    Maintainer: Michael Andres <ma@suse.de>
00017 
00018 /-*/
00019 #ifndef NCurses_h
00020 #define NCurses_h
00021 
00022 #include <iostream>
00023 #include <string>
00024 #include <set>
00025 
00026 using namespace std;
00027 
00028 #include <YCP.h>
00029 #include "YEvent.h"
00030 
00031 #include <curses.h>     /* curses.h: #define  NCURSES_CH_T cchar_t */
00032 #include <wchar.h>
00033 
00034 #include "ncursesw.h"
00035 #include "ncursesp.h"
00036 #include "position.h"
00037 #include "NCstyle.h"
00038 
00039 class NCWidget;
00040 class NCDialog;
00041 
00043 
00044 class NCursesError {
00045 
00046   public:
00047 
00048     int    errval_i;
00049     string errmsg_t;
00050 
00051     NCursesError( char * msg = "unknown error", ... );
00052     NCursesError( int val, char * msg = "unknown error", ... );
00053 
00054     virtual ~NCursesError() {}
00055 
00056     NCursesError & NCError( char * msg = "unknown error", ... );
00057     NCursesError & NCError( int val, char * msg = "unknown error", ... );
00058 
00059     virtual const char * location() const { return "NCurses"; }
00060 };
00061 
00062 extern std::ostream & operator<<( std::ostream & STREAM, const NCursesError & OBJ );
00063 
00065 
00067 
00068 class NCursesEvent {
00069 
00070   public:
00071 
00072     enum Type {
00073       handled = -1,
00074       none    = 0,
00075       cancel,
00076       timeout,
00077       button,
00078       menu,
00079       key
00080     };
00081 
00082     enum DETAIL {
00083       NODETAIL   = -1,
00084       CONTINUE   = -2,
00085       USERDEF    = -3
00086     };
00087 
00088     Type       type;
00089     NCWidget * widget;
00090     YCPValue   selection;       // used for MenuEvent (the menu selection)
00091 
00092     YCPValue    result;         // can be used for any result
00093     
00094     string      keySymbol;      // used for KeyEvent (symbol pressed key)
00095     
00096     int        detail;
00097     
00098     YEvent::EventReason reason;
00099 
00100     NCursesEvent( Type t = none, YEvent::EventReason r = YEvent::UnknownReason )
00101       : type     ( t )
00102       , widget   ( 0 )
00103       , selection( YCPNull() )
00104       , result   ( YCPNull() )
00105       , detail   ( NODETAIL )
00106       , reason   ( r )
00107     {}
00108     virtual ~NCursesEvent() {}
00109 
00110     // not operator bool() which would be propagated to almost everything ;)
00111     operator void*() const { return type != none ? (void*)1 : (void*)0; }
00112 
00113     bool operator==( const NCursesEvent & e ) const { return type == e.type; }
00114     bool operator!=( const NCursesEvent & e ) const { return type != e.type; }
00115 
00116     bool isReturnEvent()   const { return type > none; }
00117     bool isInternalEvent() const { return type < none; }
00118 
00119     
00120     // Some predefined events that can be used as return values
00121     
00122     static const NCursesEvent Activated;
00123     static const NCursesEvent SelectionChanged;
00124     static const NCursesEvent ValueChanged;
00125 };
00126 
00127 extern std::ostream & operator<<( std::ostream & STREAM, const NCursesEvent & OBJ );
00128 
00130 
00132 //
00133 //      CLASS NAME : NCurses
00134 //
00135 //      DESCRIPTION :
00136 //
00137 class NCurses {
00138 
00139   friend std::ostream & operator<<( std::ostream & STREAM, const NCurses & OBJ );
00140 
00141   NCurses & operator=( const NCurses & );
00142   NCurses            ( const NCurses & );
00143 
00144   private:
00145 
00146     static NCurses * myself;
00147 
00148     static WINDOW * ripped_w;
00149     static int ripinit( WINDOW * , int );
00150 
00151   protected:
00152 
00153     SCREEN * theTerm;
00154     string   myTerm;
00155     string   envTerm;
00156     WINDOW * title_w;
00157     string   title_t;
00158 
00159     NCstyle *      styleset;
00160     NCursesPanel * stdpan;
00161 
00162     void init();
00163     bool initialized() const { return stdpan; }
00164 
00165     virtual bool title_line()   { return true; }
00166     virtual bool want_colors()  { return true; }
00167     virtual void setup_screen();
00168     virtual void init_title();
00169     virtual void init_screen();
00170 
00171   public:
00172 
00173     NCurses();
00174     virtual ~NCurses();
00175 
00176     static int cols()  { return ::COLS; }
00177     static int lines() { return ::LINES; }
00178 
00179     void run();
00180 
00181   public:
00182 
00183     static const NCstyle & style();
00184 
00185     static void Update();
00186     static void Redraw();
00187     static void Refresh();
00188     static void SetTitle( const string & str );
00189     static void ScreenShot( const string & name = "screen.shot" );
00190 
00191     static void drawTitle();
00192 
00193   public:
00194     // actually not for public use
00195     static void ForgetDlg( NCDialog * dlg_r );
00196     static void RememberDlg( NCDialog * dlg_r );
00197     static void ResizeEvent();
00198   private:
00199     static set<NCDialog*> _knownDlgs;
00200 };
00201 
00203 
00204 #define CTRL(x)     ((x) & 0x1f)
00205 #define KEY_TAB     011
00206 #define KEY_RETURN  012
00207 #define KEY_ESC     033
00208 #define KEY_SPACE   040
00209 #define KEY_HOTKEY  KEY_MAX+1
00210 
00212 
00213 #endif // NCurses_h

Generated on Wed Nov 12 04:52:32 2008 for yast2-ncurses by  doxygen 1.3.9.1