00001 #ifndef _GHTML2_PRIV_H_
00002 #define _GHTML2_PRIV_H_
00003
00004 #include "GCss.h"
00005
00006 namespace Html2
00007 {
00008
00010
00012 enum HtmlTag
00013 {
00014 CONTENT,
00015 CONDITIONAL,
00016 ROOT,
00017 TAG_UNKNOWN,
00018 TAG_HTML,
00019 TAG_HEAD,
00020 TAG_BODY,
00021 TAG_B,
00022 TAG_I,
00023 TAG_U,
00024 TAG_P,
00025 TAG_BR,
00026 TAG_UL,
00027 TAG_OL,
00028 TAG_LI,
00029 TAG_FONT,
00030 TAG_A,
00031 TAG_TABLE,
00032 TAG_TR,
00033 TAG_TD,
00034 TAG_IMG,
00035 TAG_DIV,
00036 TAG_SPAN,
00037 TAG_CENTER,
00038 TAG_META,
00039 TAG_TBODY,
00040 TAG_STYLE,
00041 TAG_SCRIPT,
00042 TAG_STRONG,
00043 TAG_BLOCKQUOTE,
00044 TAG_PRE,
00045 TAG_H1,
00046 TAG_H2,
00047 TAG_H3,
00048 TAG_H4,
00049 TAG_H5,
00050 TAG_H6,
00051 TAG_HR,
00052 TAG_IFRAME,
00053 TAG_LINK,
00054 };
00055
00056 enum TagInfoFlags
00057 {
00058 TI_NONE = 0x00,
00059 TI_NEVER_CLOSES = 0x01,
00060 TI_NO_TEXT = 0x02,
00061 TI_BLOCK = 0x04,
00062 TI_TABLE = 0x08,
00063 };
00064
00066
00068 class GFlowRect;
00069 class GFlowRegion;
00070
00071 struct GTagHit
00072 {
00073 GTag *Hit;
00074 int Near;
00075
00076 GFlowRect *Block;
00077 int Index;
00078
00079 GTagHit()
00080 {
00081 Hit = 0;
00082 Block = 0;
00083 Near = -1;
00084 Index = -1;
00085 }
00086
00087 bool operator <(GTagHit &h)
00088 {
00089 if (!Hit)
00090 return false;
00091
00092 if (!h.Hit)
00093 return true;
00094
00095 LgiAssert( Near >= 0 &&
00096 h.Near >= 0);
00097
00098 if (Near < h.Near)
00099 return true;
00100
00101 return false;
00102 }
00103 };
00104
00105 struct GInfo
00106 {
00107 public:
00108 HtmlTag Id;
00109 char *Tag;
00110 char *ReattachTo;
00111 int Flags;
00112
00113 bool NeverCloses() { return TestFlag(Flags, TI_NEVER_CLOSES); }
00114 bool NoText() { return TestFlag(Flags, TI_NO_TEXT); }
00115 bool Block() { return TestFlag(Flags, TI_BLOCK); }
00116 };
00117
00118 class GLength
00119 {
00120 protected:
00121 float d;
00122 float PrevAbs;
00123 GCss::LengthType u;
00124
00125 public:
00126 GLength();
00127 GLength(char *s);
00128
00129 bool IsValid();
00130 bool IsDynamic();
00131 float GetPrevAbs() { return PrevAbs; }
00132 operator float();
00133 GLength &operator =(float val);
00134 GCss::LengthType GetUnits();
00135 void Set(char *s);
00136 float Get(GFlowRegion *Flow, GFont *Font, bool Lock = false);
00137 float GetRaw() { return d; }
00138 };
00139
00140 class GLine : public GLength
00141 {
00142 public:
00143 int LineStyle;
00144 int LineReset;
00145 GCss::ColorDef Colour;
00146
00147 GLine();
00148 ~GLine();
00149
00150 GLine &operator =(int i);
00151 void Set(char *s);
00152 };
00153
00154 class GCellStore
00155 {
00156 class Cell
00157 {
00158 public:
00159 int x, y;
00160 GTag *Tag;
00161 };
00162
00163 List<Cell> Cells;
00164
00165 public:
00166 GCellStore(GTag *Table);
00167 ~GCellStore()
00168 {
00169 Cells.DeleteObjects();
00170 }
00171
00172 void GetSize(int &x, int &y);
00173 void GetAll(List<GTag> &All);
00174 GTag *Get(int x, int y);
00175 bool Set(GTag *t);
00176
00177 void Dump();
00178 };
00179
00180 class GFlowRect : public GRect
00181 {
00182 public:
00183 GTag *Tag;
00184 char16 *Text;
00185 int Len;
00186
00187 GFlowRect()
00188 {
00189 Tag = 0;
00190 Text = 0;
00191 Len = 0;
00192 }
00193
00194 ~GFlowRect()
00195 {
00196 }
00197
00198 int Start();
00199 bool OverlapX(int x) { return x >= x1 && x <= x2; }
00200 bool OverlapY(int y) { return y >= y1 && y <= y2; }
00201 bool OverlapX(GFlowRect *b) { return !(b->x2 < x1 || b->x1 > x2); }
00202 bool OverlapY(GFlowRect *b) { return !(b->y2 < y1 || b->y1 > y2); }
00203 };
00204
00205 class GArea : public List<GFlowRect>
00206 {
00207 public:
00208 ~GArea();
00209
00210 GRect *TopRect(GRegion *c);
00211 void FlowText(GTag *Tag, GFlowRegion *c, GFont *Font, char16 *Text, GCss::LengthType Align);
00212 };
00213
00214 class GTag : public GDom, public GCss
00215 {
00216 static bool Selected;
00217 friend class HtmlEdit;
00218
00219 GHashTbl<const char*, char*> Attr;
00220
00221
00222 GAutoWString Txt, PreTxt;
00223
00224
00225 void _Dump(GStringPipe &Buf, int Depth);
00226 void _TraceOpenTags();
00227
00228
00229 GFont *NewFont();
00230 int NearestChar(GFlowRect *Fr, int x, int y);
00231 GTag *HasOpenTag(char *t);
00232 GTag *PrevTag();
00233 GRect ChildBounds();
00234 bool GetWidthMetrics(uint16 &Min, uint16 &Max);
00235 void LayoutTable(GFlowRegion *f);
00236 void BoundParents();
00237 bool PeekTag(char *s, char *tag);
00238 GTag *GetTable();
00239 char *NextTag(char *s);
00240 void ZeroTableElements();
00241 bool OnUnhandledColor(GCss::ColorDef *def, char *&s);
00242
00243 COLOUR _Colour(bool Fore);
00244 COLOUR GetFore() { return _Colour(true); }
00245 COLOUR GetBack() { return _Colour(false); }
00246
00247 public:
00248
00249 HtmlTag TagId;
00250 char *Tag;
00251 GAutoString Condition;
00252 char *HtmlId;
00253 GInfo *Info;
00254 int TipId;
00255 bool WasClosed;
00256 bool IsBlock;
00257
00258
00259 GHtml2 *Html;
00260 GTag *Parent;
00261 List<GTag> Tags;
00262 bool HasChild(GTag *c);
00263 bool Attach(GTag *Child, int Idx = -1);
00264 void Detach();
00265 GTag *GetBlockParent(int *Idx = 0);
00266 GFont *GetFont();
00267
00268
00269 GdcPt2 Pos;
00270 GdcPt2 Size;
00271 GFont *Font;
00272
00273
00274 GAutoPtr<GSurface> Image;
00275 void SetImage(char *uri, GSurface *i);
00276 void LoadImage(char *Uri);
00277 void LoadImages();
00278 void ImageLoaded(char *uri, GSurface *img, int &Used);
00279
00280
00281 GdcPt2 Cell;
00282 GdcPt2 Span;
00283 uint16 MinContent, MaxContent;
00284 GCellStore *Cells;
00285 #ifdef _DEBUG
00286 int Debug;
00287 #endif
00288
00289
00290 int Cursor;
00291 int Selection;
00292 GArea TextPos;
00293
00294 GTag(GHtml2 *h, GTag *p);
00295 ~GTag();
00296
00297
00298 void OnChange(PropType Prop);
00299
00300
00301 bool Get(const char *attr, char *&val) { val = Attr.Find(attr); return val != 0; }
00302 void Set(const char *attr, const char *val);
00303
00304
00305 char16 *Text() { return Txt; }
00306 void Text(char16 *t) { Txt.Reset(t); TextPos.Empty(); }
00307 char16 *PreText() { return PreTxt; }
00308 void PreText(char16 *t) { PreTxt.Reset(t); TextPos.Empty(); }
00309
00310 int GetTextStart();
00311 char *Dump();
00312 char16 *CleanText(char *s, int len, bool ConversionAllowed = true, bool KeepWhiteSpace = false);
00313 char *ParseHtml(char *Doc, int Depth, bool InPreTag = false, bool *BackOut = 0);
00314 char *ParseText(char *Doc);
00315 void SetStyle();
00316 void SetCssStyle(char *Style);
00317 void OnFlow(GFlowRegion *Flow);
00318 void OnPaintBorder(GSurface *pDC);
00319 void OnPaint(GSurface *pDC);
00320 void SetSize(GdcPt2 &s);
00321 void SetTag(char *Tag);
00322 GTagHit GetTagByPos(int x, int y);
00323 GTag *GetTagByName(char *Name);
00324 void CopyClipboard(GBytePipe &p);
00325 GTag *IsAnchor(GAutoString *Uri);
00326 bool CreateSource(GStringPipe &p, int Depth = 0, bool LastWasBlock = true);
00327 bool GetVariant(const char *Name, GVariant &Value, char *Array = 0);
00328 bool SetVariant(const char *Name, GVariant &Value, char *Array = 0);
00329 void Find(int TagType, GArray<GTag*> &Tags);
00330 GTag *GetAnchor(char *Name);
00331
00332
00333 bool OnMouseClick(GMouse &m);
00334 void Invalidate();
00335
00336
00337 int RelX() { return Pos.x + MarginLeft().Value; }
00338 int RelY() { return Pos.y + MarginTop().Value; }
00339 int AbsX();
00340 int AbsY();
00341 GRect GetRect(bool Client = true);
00342 GCss::LengthType GetAlign(bool x);
00343
00344
00345 GTag *GetTableCell(int x, int y);
00346 GdcPt2 GetTableSize();
00347 };
00348
00349 }
00350
00351 #endif