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

NCtext.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:       NCtext.h
00014 
00015    Author:     Michael Andres <ma@suse.de>
00016    Maintainer: Michael Andres <ma@suse.de>
00017 
00018 /-*/
00019 #ifndef NCtext_h
00020 #define NCtext_h
00021 
00022 #include <iosfwd>
00023 
00024 #include <list>
00025 using namespace std;
00026 
00027 #include "NCstring.h"
00028 #include "NCWidget.h"
00029 class NCursesWindow;
00030 
00032 //
00033 //      CLASS NAME : NCtext
00034 //
00035 //      DESCRIPTION :
00036 //
00037 class NCtext {
00038 
00039   friend std::ostream & operator<<( std::ostream & STREAM, const NCtext & OBJ );
00040 
00041   public:
00042 
00043     typedef list<NCstring>::iterator       iterator;
00044     typedef list<NCstring>::const_iterator const_iterator;
00045 
00046   private:
00047 
00048     static const NCstring emptyStr;
00049 
00050   protected:
00051 
00052     list<NCstring> mtext;
00053 
00054     virtual void lset( const NCstring & ntext );
00055     void lbrset( const NCstring & ntext, size_t columns ); 
00056 
00057   public:
00058 
00059     NCtext( const NCstring & nstr = "" );
00060     NCtext( const NCstring & nstr, size_t columns );
00061 
00062     virtual ~NCtext();
00063 
00064     unsigned Lines()   const;
00065     size_t Columns() const;
00066 
00067     void append( const NCstring & line );
00068     
00069     const list<NCstring> & Text() const { return mtext; }
00070     const NCstring &       operator[]( std::wstring::size_type idx ) const;
00071 
00072     const_iterator begin() const { return mtext.begin(); }
00073     const_iterator end()   const { return mtext.end(); }
00074 };
00075 
00077 
00079 //
00080 //      CLASS NAME : NClabel
00081 //
00082 //      DESCRIPTION :
00083 //
00084 class NClabel : protected NCtext {
00085 
00086   friend std::ostream & operator<<( std::ostream & STREAM, const NClabel & OBJ );
00087 
00088   protected:
00089 
00090     std::wstring::size_type hotline;
00091 
00092     void stripHotkey();
00093 
00094     virtual void lset( const NCstring & ntext ) {
00095       NCtext::lset( ntext );
00096       stripHotkey();
00097     }
00098 
00099   public:
00100 
00101     NClabel( const NCstring & nstr = "" )
00102       : NCtext( nstr )
00103     { stripHotkey(); }
00104 
00105     virtual ~NClabel() {}
00106 
00107   public:
00108 
00109     size_t   width()  const { return Columns(); }
00110     unsigned height() const { return Lines(); }
00111     wsze     size()   const { return wsze( Lines(), Columns() ); }
00112     const list<NCstring> & getText() const { return Text(); }
00113     
00114     void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
00115                  const wrect & dim,
00116                  const NC::ADJUST adjust = NC::TOPLEFT,
00117                  bool fillup = true ) const;
00118 
00119     //
00120     void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
00121                  const NC::ADJUST adjust = NC::TOPLEFT,
00122                  bool fillup = true ) const {
00123       drawAt( w, style, hotstyle, wrect( 0, -1 ), adjust, fillup );
00124     }
00125 
00126     void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
00127                  const wpos & pos,
00128                  const NC::ADJUST adjust = NC::TOPLEFT,
00129                  bool fillup = true ) const {
00130       drawAt( w, style, hotstyle, wrect( pos, -1 ), adjust, fillup );
00131     }
00132 
00133     void drawAt( NCursesWindow & w, chtype style, chtype hotstyle,
00134                  const wpos & pos, const wsze & sze,
00135                  const NC::ADJUST adjust = NC::TOPLEFT,
00136                  bool fillup = true ) const {
00137       drawAt( w, style, hotstyle, wrect( pos, sze ), adjust, fillup );
00138     }
00139 
00140     //
00141     void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
00142                  const NC::ADJUST adjust = NC::TOPLEFT,
00143                  bool fillup = true ) const {
00144       drawAt( w, istyle.label, istyle.hint, wrect( 0, -1 ), adjust, fillup );
00145     }
00146 
00147     void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
00148                  const wpos & pos,
00149                  const NC::ADJUST adjust = NC::TOPLEFT,
00150                  bool fillup = true ) const {
00151       drawAt( w, istyle.label, istyle.hint, wrect( pos, -1 ), adjust, fillup );
00152     }
00153 
00154     void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
00155                  const wpos & pos, const wsze & sze,
00156                  const NC::ADJUST adjust = NC::TOPLEFT,
00157                  bool fillup = true ) const {
00158       drawAt( w, istyle.label, istyle.hint, wrect( pos, sze ), adjust, fillup );
00159     }
00160 
00161     void drawAt( NCursesWindow & w, const NCstyle::StItem & istyle,
00162                  const wrect & dim,
00163                  const NC::ADJUST adjust = NC::TOPLEFT,
00164                  bool fillup = true ) const {
00165       drawAt( w, istyle.label, istyle.hint, dim, adjust, fillup );
00166     }
00167 
00168     //
00169 
00170 
00171     bool        hasHotkey() const { return hotline != wstring::npos; }
00172     wchar_t     hotkey() const { return hasHotkey() ? operator[]( hotline ).hotkey() : L'\0'; }
00173     std::wstring::size_type   hotpos() const { return hasHotkey() ? operator[]( hotline ).hotpos() : wstring::npos; }
00174 };
00175 
00177 
00178 #endif // NCtext_h

Generated on Wed Sep 5 17:18:55 2007 for yast2-ncurses by doxygen 1.3.6