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