00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00034
00035
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
00060 private:
00061
00062 NCstring text;
00063
00064 bool plainText;
00065
00066 unsigned textwidth;
00067 unsigned cl;
00068 unsigned cc;
00069 unsigned cindent;
00070 bool atbol;
00071
00072 bool preTag;
00073
00074
00075 unsigned Tattr;
00076
00077 static const unsigned Tfontmask = 0xff00;
00078 enum TOKEN {
00079 T_UNKNOWN = 0x0000,
00080 T_IGNORE = 0x0001,
00081 T_BR = 0x0002,
00082 T_PAR = 0x0004,
00083 T_LEVEL = 0x0008,
00084 T_LI = 0x0010,
00085 T_PLAIN = 0x0012,
00086
00087 T_BOLD = 0x0100,
00088 T_IT = 0x0200,
00089 T_TT = 0x0400,
00090 T_ANC = 0x0800,
00091 T_HEAD = 0x1000
00092 };
00093
00094 private:
00095
00096 static const unsigned listindent;
00097 static const wstring listleveltags;
00098
00099 stack<int> liststack;
00100
00101 void PadChangeLevel( bool down, int tag );
00102 void PadSetLevel();
00103 size_t textWidth( wstring wstr );
00104
00105 private:
00106
00107 class Anchor {
00108
00109 public:
00110
00111 static const unsigned unset = (unsigned)-1;
00112
00113 unsigned sline;
00114 unsigned scol;
00115 unsigned eline;
00116 unsigned ecol;
00117
00118 wstring target;
00119
00120 Anchor() {
00121 sline = scol = eline = ecol = unset;
00122 }
00123 Anchor( int sl, int sc ) {
00124 open( sl, sc );
00125 }
00126 void open( int sl, int sc ) {
00127 sline = sl;
00128 scol = sc;
00129 eline = ecol = unset;
00130 target = L"";
00131 }
00132 void close( int el, int ec ) {
00133 eline = el;
00134 ecol = ec;
00135 }
00136 bool valid() {
00137 if ( sline == unset || scol == unset
00138 || eline == unset || ecol == unset )
00139 return false;
00140 if ( eline == sline && ecol <= scol
00141 || eline < sline )
00142 return false;
00143 return true;
00144 }
00145 bool within( unsigned firstvisible, unsigned nextinvisible ) {
00146 return sline < nextinvisible && eline >= firstvisible;
00147 }
00148 void draw( NCPad & pad, const chtype attr, int color );
00149 };
00150
00151 static const bool showLinkTarget;
00152
00153 Anchor canchor;
00154 vector<Anchor> anchors;
00155 unsigned armed;
00156
00157 unsigned vScrollFirstvisible;
00158 unsigned vScrollNextinvisible;
00159
00160 void openAnchor( wstring args );
00161 void closeAnchor();
00162
00163 void arm( unsigned i );
00164 void disarm() { arm( Anchor::unset ); }
00165
00166 private:
00167
00168 void PadSetAttr();
00169
00170 void DrawPlainPad();
00171 void DrawHTMLPad();
00172
00173 void PadNL();
00174 void PadBOL();
00175 void PadWS( const bool tab = false );
00176 void PadTXT( const wchar_t * sch, const unsigned len );
00177 void PadPlainTXT( const wchar_t * sch, const unsigned len );
00178 bool PadTOKEN( const wchar_t * sch, const wchar_t *& ech );
00179
00180 protected:
00181
00182 virtual const char * location() const { return "NCRichText"; }
00183
00184 virtual void wRedraw();
00185 virtual void wRecoded();
00186
00187 virtual NCPad * CreatePad();
00188 virtual void DrawPad();
00189
00190 virtual void HScroll( unsigned total, unsigned visible, unsigned start );
00191 virtual void VScroll( unsigned total, unsigned visible, unsigned start );
00192
00193 virtual bool handleInput( wint_t key );
00194
00195 public:
00196
00197 NCRichText( NCWidget * parent, const YWidgetOpt & opt,
00198 const YCPString & text );
00199 virtual ~NCRichText();
00200
00201 virtual long nicesize( YUIDimension dim );
00202 virtual void setSize( long newwidth, long newheight );
00203
00204 virtual void setLabel( const YCPString & nlabel );
00205
00206 virtual NCursesEvent wHandleInput( wint_t key );
00207
00208 virtual void setText( const YCPString & ntext );
00209
00210 virtual void setEnabling( bool do_bv ) { NCWidget::setEnabling( enabled=do_bv ); }
00211
00212 virtual bool setKeyboardFocus() {
00213 if ( !grabFocus() )
00214 return YWidget::setKeyboardFocus();
00215 return true;
00216 }
00217 };
00218
00220
00221 #endif // NCRichText_h