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

NCRichText.h

Go to the documentation of this file.
00001 
00002 /*---------------------------------------------------------------------\
00003 |                                                                      |
00004 |                      __   __    ____ _____ ____                      |
00005 |                      \ \ / /_ _/ ___|_   _|___ \                     |
00006 |                       \ V / _` \___ \ | |   __) |                    |
00007 |                        | | (_| |___) || |  / __/                     |
00008 |                        |_|\__,_|____/ |_| |_____|                    |
00009 |                                                                      |
00010 |                               core system                            |
00011 |                                                        (C) SuSE GmbH |
00012 \----------------------------------------------------------------------/
00013 
00014    File:       NCRichText.h
00015 
00016    Author:     Michael Andres <ma@suse.de>
00017    Maintainer: Michael Andres <ma@suse.de>
00018 
00019 /-*/
00020 #ifndef NCRichText_h
00021 #define NCRichText_h
00022 
00023 #include <iosfwd>
00024 #include <stack>
00025 
00026 #include "YRichText.h"
00027 #include "NCPadWidget.h"
00028 
00029 class NCRichText;
00030 
00032 //
00033 //      CLASS NAME : NCRichText
00034 //
00035 //      DESCRIPTION :
00036 //
00037 class NCRichText : public YRichText, public NCPadWidget {
00038 
00039   friend std::ostream & operator<<( std::ostream & STREAM, const NCRichText & OBJ );
00040 
00041   NCRichText & operator=( const NCRichText & );
00042   NCRichText            ( const NCRichText & );
00043 
00044   private:
00045 
00050     static std::map<std::wstring, std::wstring> _charentity;
00051 
00058     static const wstring entityLookup( const std::wstring & val_r );
00059 
00063     static const wstring filterEntities( const std::wstring & text );
00064 
00065   private:
00066 
00067     NCstring text;
00068 
00069     bool plainText;
00070 
00071     unsigned textwidth;
00072     unsigned cl;
00073     unsigned cc;
00074     unsigned cindent;
00075     bool     atbol;
00076 
00077     bool     preTag;            // default is false; set true
00078                                 // if <pre> tag is found
00079     
00080     unsigned Tattr;
00081 
00082     static const unsigned Tfontmask = 0xff00;
00083     enum TOKEN {
00084       T_UNKNOWN = 0x0000,
00085       T_IGNORE  = 0x0001,
00086       T_BR      = 0x0002,
00087       T_PAR     = 0x0004,
00088       T_LEVEL   = 0x0008,
00089       T_LI      = 0x0010,
00090       T_PLAIN   = 0x0012,
00091       // font
00092       T_BOLD    = 0x0100,
00093       T_IT      = 0x0200,
00094       T_TT      = 0x0400,
00095       T_ANC     = 0x0800,
00096       T_HEAD    = 0x1000
00097     };
00098 
00099   private:
00100 
00101     static const unsigned listindent;
00102     static const wstring   listleveltags;
00103 
00104     stack<int> liststack;
00105 
00106     void PadChangeLevel( bool down, int tag );
00107     void PadSetLevel();
00108     size_t textWidth( wstring wstr );
00109 
00110   private:
00111 
00112     class Anchor {
00113 
00114       public:
00115 
00116         static const unsigned unset = (unsigned)-1;
00117 
00118         unsigned sline;
00119         unsigned scol;
00120         unsigned eline;
00121         unsigned ecol;
00122 
00123         wstring target;
00124 
00125         Anchor() {
00126           sline = scol = eline = ecol = unset;
00127         }
00128         Anchor( int sl, int sc ) {
00129           open( sl, sc );
00130         }
00131         void open( int sl, int sc ) {
00132           sline = sl;
00133           scol  = sc;
00134           eline = ecol = unset;
00135           target = L"";
00136         }
00137         void close( int el, int ec ) {
00138           eline = el;
00139           ecol  = ec;
00140         }
00141         bool valid() {
00142           if (    sline == unset || scol == unset
00143                || eline == unset || ecol == unset  )
00144             return false;
00145           if (    eline == sline && ecol <= scol
00146                || eline < sline )
00147             return false;
00148           return true;
00149         }
00150         bool within( unsigned firstvisible, unsigned nextinvisible ) {
00151           return sline < nextinvisible && eline >= firstvisible;
00152         }
00153         void draw( NCPad & pad, const chtype attr, int color );
00154     };
00155 
00156     static const bool showLinkTarget;
00157 
00158     Anchor         canchor;
00159     vector<Anchor> anchors;
00160     unsigned       armed;
00161 
00162     unsigned vScrollFirstvisible;
00163     unsigned vScrollNextinvisible;
00164 
00165     void openAnchor( wstring args );
00166     void closeAnchor();
00167 
00168     void arm( unsigned i );
00169     void disarm() { arm( Anchor::unset ); }
00170 
00171   private:
00172 
00173     void PadSetAttr();
00174 
00175     void DrawPlainPad();
00176     void DrawHTMLPad();
00177 
00178     void PadNL();
00179     void PadBOL();
00180     void PadWS( const bool tab = false );
00181     void PadTXT( const wchar_t * sch, const unsigned len );
00182     void PadPlainTXT( const wchar_t * sch, const unsigned len );   
00183     bool PadTOKEN( const wchar_t * sch, const wchar_t *& ech );
00184 
00185   protected:
00186 
00187     virtual const char * location() const { return "NCRichText"; }
00188 
00189     virtual void wRedraw();
00190     virtual void wRecoded();
00191 
00192     virtual NCPad * CreatePad();
00193     virtual void    DrawPad();
00194 
00195     virtual void HScroll( unsigned total, unsigned visible, unsigned start );
00196     virtual void VScroll( unsigned total, unsigned visible, unsigned start );
00197 
00198     virtual bool handleInput( wint_t key );
00199 
00200   public:
00201 
00202     NCRichText( NCWidget * parent, const YWidgetOpt & opt,
00203                 const YCPString & text );
00204     virtual ~NCRichText();
00205 
00206     virtual long nicesize( YUIDimension dim );
00207     virtual void setSize( long newwidth, long newheight );
00208 
00209     virtual void setLabel( const YCPString & nlabel );
00210 
00211     virtual NCursesEvent wHandleInput( wint_t key );
00212 
00213     virtual void setText( const YCPString & ntext );
00214 
00215     virtual void setEnabling( bool do_bv ) { NCWidget::setEnabling( enabled=do_bv ); }
00216 
00217     virtual bool setKeyboardFocus() {
00218       if ( !grabFocus() )
00219         return YWidget::setKeyboardFocus();
00220       return true;
00221     }
00222 };
00223 
00225 
00226 #endif // NCRichText_h

Generated on Wed Sep 14 10:52:54 2005 for yast2-ncurses by  doxygen 1.4.4