00001 #ifndef CSHTMLElement_h
00002 #define CSHTMLElement_h
00003
00004
00005
00006 #ifdef WIN32
00007 #pragma warning(disable : 4786 )
00008 #endif
00009
00010 #include <vector>
00011 #include <string>
00012 #include <map>
00013 #include "CSTypes.h"
00014
00015 #include "CSGrafikElement.h"
00016 #include "CSLog.h"
00017 #include "CSTypes.h"
00018 #include "CSStringlist.h"
00019 #include "CSIcon.h"
00020 #include "CSHTMLHelper.h"
00021 #include "CSPicture.h"
00022 #include "CSPanel.h"
00023 #include "CSMessageListener.h"
00024 #include "CSMessageBox.h"
00025
00026 class HTMLCursor;
00027 class HTMLElement;
00028
00029 typedef std::vector<HTMLElement *> HTMLElements;
00030 typedef std::map<std::string, int> HTMLTagMap;
00031
00032 const int HTML_HTML = 1;
00033 const int HTML_HEAD = 2;
00034 const int HTML_TITLE = 3;
00035 const int HTML_BODY = 4;
00036 const int HTML_H1 = 5;
00037 const int HTML_H2 = 6;
00038 const int HTML_H3 = 7;
00039 const int HTML_H4 = 8;
00040 const int HTML_H5 = 9;
00041 const int HTML_P = 10;
00042 const int HTML_BR = 11;
00043 const int HTML_HL = 12;
00044 const int HTML_PRE = 13;
00045 const int HTML_IMG = 14;
00046 const int HTML_A = 15;
00047 const int HTML_B = 16;
00048 const int HTML_I = 17;
00049 const int HTML_DL = 18;
00050 const int HTML_DD = 19;
00051 const int HTML_DT = 20;
00052 const int HTML_OL = 21;
00053 const int HTML_UL = 22;
00054 const int HTML_LI = 23;
00055 const int HTML_TABLE = 24;
00056 const int HTML_TR = 25;
00057 const int HTML_TH = 26;
00058 const int HTML_TT = 27;
00059
00060 const int HTML_OUTPUT_NONE = 0;
00061 const int HTML_OUTPUT_IMAGE = 1;
00062 const int HTML_OUTPUT_TEXT = 2;
00063 const int HTML_OUTPUT_PANEL = 3;
00064
00065 class HTMLCompiled;
00066 class CSHTMLPanel;
00067
00068 class HTMLCursor
00069 {
00070 friend HTMLElement;
00071 friend CSHTMLPanel;
00072 private:
00073 CSFont *mFont;
00074 int mFontSize;
00075 int mStyle;
00076
00077 int mXPos;
00078 int mYPos;
00079 int mXPosMax;
00080 int mCurrentStartX;
00081 int mAddX;
00082 int nextAdd;
00083 int mPenColor;
00084 int mBackgroundColor;
00085 int mLinkColor;
00086 int mTextalignment;
00087 int mListCounter;
00088 bool mInBody;
00089 bool mInPre;
00090 public:
00091 HTMLCursor()
00092 {
00093 mInBody = false;
00094 mPenColor = 0xffffff;
00095 mLinkColor = 0x3030d0;
00096 mBackgroundColor = 0xd0d0d0;
00097 mXPosMax = 0;
00098 mInPre = false;
00099 mAddX = 0;
00100 mListCounter = -1;
00101 mStyle = 0;
00102 }
00103 };
00104
00105 typedef std::vector<SDL_Rect *> Positions;
00106
00107 class HTMLElement
00108 {
00109 private:
00110 static HTMLTagMap *mHTMLTagMap;
00111 static int getTagType(CSHTMLNode &node);
00112 static StringVector *tokenifyText(const std::string &text);
00113
00114 CSGrafikElements mGrafikElements;
00115 HTMLElements mElements;
00116 HTMLElement *mParent;
00117 Positions mPositions;
00118 bool mPositionsStored;
00119
00120 int mX;
00121 int mY;
00122 int mWidth;
00123 int mHeight;
00124 int mXOffset;
00125 int mYOffset;
00126 CSHTMLNode mNode;
00127 std::string getChildrenAsText();
00128 std::string formatURL(const std::string &rawURL);
00129 void addPostion(int x, int y, int w, int h);
00130 void setParent(HTMLElement *parent){mParent = parent;}
00131 HTMLElement *getParent(){return mParent;}
00132
00133 public:
00134 static const char *CLASS;
00135 static int getColorFromString(std::string acolor);
00136 virtual std::string getType() {return (std::string) CLASS;}
00137
00138 HTMLElement(CSHTMLNode node);
00139 ~HTMLElement();
00140 HTMLCursor buildDisplay(HTMLCursor Cursor, CSGrafikElement *destination, int parentViewportWidth, std::string &title);
00141 int getX() {return mX;}
00142 int getY() {return mY;}
00143 int getWidth() {return mWidth;}
00144 int getHeight() {return mHeight;}
00145 void clearPosition();
00146 void clearCompiled();
00147 HTMLElement *checkPostion(int x, int y);
00148 std::string getText()
00149 {
00150 if (mNode.isText()) return mNode.getValue();
00151 return std::string();
00152 }
00153
00154 int getTagType();
00155 HTMLElement *getAncestorType(int type);
00156 HTMLElement *getChildType(int type, std::string attributName, std::string attributeValue);
00157 std::string getAttributValue(std::string attributeName);
00158 int getFirstYPostion();
00159 };
00160
00161
00162 #endif // CSHTMLElement_h