📄 html.hpp
字号:
// HTML tagclass NCBI_XHTML_EXPORT CHTMLElement: public CHTMLInlineElement{ typedef CHTMLInlineElement CParent;public: CHTMLElement(const char* tagname) : CParent(tagname) { } CHTMLElement(const char* tagname, const char* text) : CParent(tagname, text) { } CHTMLElement(const char* tagname, const string& text) : CParent(tagname, text) { } CHTMLElement(const char* tagname, CNCBINode* node) : CParent(tagname, node) { } CHTMLElement(const string& tagname) : CParent(tagname) { } CHTMLElement(const string& tagname, const char* text) : CParent(tagname, text) { } CHTMLElement(const string& tagname, const string& text) : CParent(tagname, text) { } CHTMLElement(const string& tagname, CNCBINode* node) : CParent(tagname, node) { } ~CHTMLElement(void); // Print tag close. virtual CNcbiOstream& PrintEnd(CNcbiOstream &, TMode mode); };// HTML block element.class NCBI_XHTML_EXPORT CHTMLBlockElement: public CHTMLElement{ typedef CHTMLElement CParent;public: CHTMLBlockElement(const char* tagname) : CParent(tagname) { } CHTMLBlockElement(const char* tagname, const char* text) : CParent(tagname, text) { } CHTMLBlockElement(const char* tagname, const string& text) : CParent(tagname, text) { } CHTMLBlockElement(const char* tagname, CNCBINode* node) : CParent(tagname, node) { } CHTMLBlockElement(const string& tagname) : CParent(tagname) { } CHTMLBlockElement(const string& tagname, const char* text) : CParent(tagname, text) { } CHTMLBlockElement(const string& tagname, const string& text) : CParent(tagname, text) { } CHTMLBlockElement(const string& tagname, CNCBINode* node) : CParent(tagname, node) { } ~CHTMLBlockElement(void); // Close tag. virtual CNcbiOstream& PrintEnd(CNcbiOstream &, TMode mode); };// HTML comment.class NCBI_XHTML_EXPORT CHTMLComment : public CHTMLNode{ typedef CHTMLNode CParent; static const char sm_TagName[];public: CHTMLComment(void) : CParent(sm_TagName) { } CHTMLComment(const char* text) : CParent(sm_TagName) { AppendPlainText(text); } CHTMLComment(const string& text) : CParent(sm_TagName) { AppendPlainText(text); } CHTMLComment(CNCBINode* node) : CParent(sm_TagName) { AppendChild(node); } ~CHTMLComment(void); virtual CNcbiOstream& Print(CNcbiOstream& out, TMode mode = eHTML); virtual CNcbiOstream& PrintBegin(CNcbiOstream &, TMode mode); virtual CNcbiOstream& PrintEnd(CNcbiOstream &, TMode mode);};// <list> tag.class NCBI_XHTML_EXPORT CHTMLListElement : public CHTMLElement{ typedef CHTMLElement CParent;public: CHTMLListElement(const char* tagname, bool compact = false) : CParent(tagname) { if ( compact ) { SetCompact(); } } CHTMLListElement(const char* tagname, const char* type, bool compact = false) : CParent(tagname) { SetType(type); if ( compact ) { SetCompact(); } } CHTMLListElement(const char* tagname, const string& type, bool compact = false) : CParent(tagname) { SetType(type); if ( compact ) { SetCompact(); } } ~CHTMLListElement(void); CHTMLListElement* AppendItem(const char* text); CHTMLListElement* AppendItem(const string& text); CHTMLListElement* AppendItem(CNCBINode* node); CHTMLListElement* SetType(const char* type); CHTMLListElement* SetType(const string& type); CHTMLListElement* SetCompact(void); CNcbiOstream& PrintChildren(CNcbiOstream& out, TMode mode);};// HTML special char.class NCBI_XHTML_EXPORT CHTMLSpecialChar: public CHTMLDualNode{ typedef CHTMLDualNode CParent;public: // The "html" argument will be automagically wrapped into '&...;', // e.g. 'amp' --> '&' CHTMLSpecialChar(const char* html, const char* plain, int count = 1); ~CHTMLSpecialChar(void); virtual CNcbiOstream& PrintChildren(CNcbiOstream& out, TMode mode);private: string m_Html; int m_Count;};// <html> tagclass NCBI_XHTML_EXPORT CHTML_html : public CHTMLElement{ // CParent, constructors, destructor. DECLARE_HTML_ELEMENT_COMMON_WITH_INIT(html, CHTMLElement); // Enable using popup menus, set URL for popup menu library. // If "menu_lib_url" is not defined, then using default URL. // use_dynamic_menu - enable/disable using dynamic popup menus // (default it is disabled). // NOTE: 1) If we not change value "menu_script_url", namely use default // value for it, then we can skip call this function. // 2) Dynamic menu work only in new browsers. They use one container // for all menus instead of separately container for each menu in // nondynamic mode. This parameter have effect only with eSmith // menu type. void EnablePopupMenu(CHTMLPopupMenu::EType type = CHTMLPopupMenu::eSmith, const string& menu_script_url = kEmptyStr, bool use_dynamic_menu = false);private: // Init members. void Init(void); // Print all self childrens (automatic include code for support // popup menus, if it needed). virtual CNcbiOstream& PrintChildren(CNcbiOstream& out, TMode mode); // The popup menu info structure. struct SPopupMenuInfo { SPopupMenuInfo() : m_UseDynamicMenu(false) { }; SPopupMenuInfo(const string& url, bool use_dynamic_menu) : m_Url(url), m_UseDynamicMenu(use_dynamic_menu) { } string m_Url; bool m_UseDynamicMenu; // Only for eSmith menu type. }; // The popup menus usage info. typedef map<CHTMLPopupMenu::EType, SPopupMenuInfo> TPopupMenus; TPopupMenus m_PopupMenus;};// Table classes.class CHTML_table; // Tableclass CHTML_tr; // Rowclass CHTML_tc; // Any cellclass CHTML_th; // Header cellclass CHTML_td; // Data cellclass CHTML_tc_Cache;class CHTML_tr_Cache;class CHTML_table_Cache;class NCBI_XHTML_EXPORT CHTML_tc : public CHTMLElement{ typedef CHTMLElement CParent;public: typedef unsigned TIndex; CHTML_tc(const char* tagname) : CParent(tagname), m_Parent(0) { } CHTML_tc(const char* tagname, const char* text) : CParent(tagname, text), m_Parent(0) { } CHTML_tc(const char* tagname, const string& text) : CParent(tagname, text), m_Parent(0) { } CHTML_tc(const char* tagname, CNCBINode* node) : CParent(tagname, node), m_Parent(0) { } ~CHTML_tc(void); // Type for row and column indexing. CHTML_tc* SetRowSpan(TIndex span); CHTML_tc* SetColSpan(TIndex span); void ResetTableCache(void);protected: virtual void DoSetAttribute(const string& name, const string& value, bool optional); friend class CHTML_tr; friend class CHTML_tc_Cache; CHTML_tr* m_Parent;};class NCBI_XHTML_EXPORT CHTML_tr : public CHTMLElement{ typedef CHTMLElement CParent;public: typedef unsigned TIndex; CHTML_tr(void); CHTML_tr(CNCBINode* node); CHTML_tr(const string& text); void ResetTableCache(void); virtual CNcbiOstream& PrintChildren(CNcbiOstream& out, TMode mode); virtual CNcbiOstream& PrintEnd(CNcbiOstream& out, TMode mode);protected: virtual void DoAppendChild(CNCBINode* node); void AppendCell(CHTML_tc* cell); size_t GetTextLength(TMode mode); friend class CHTML_table; friend class CHTML_tr_Cache; CHTML_table* m_Parent;};// <table> tag.class NCBI_XHTML_EXPORT CHTML_table : public CHTMLElement{ typedef CHTMLElement CParent;public: // Type for row and column indexing. typedef unsigned TIndex; enum ECellType { eAnyCell, eDataCell, eHeaderCell }; CHTML_table(void); ~CHTML_table(void); // Return row, will add rows if needed. // Throws exception if it is not left upper corner of cell. CHTML_tr* Row(TIndex row); // Get/set current insertion point. void SetCurrentCell(TIndex row, TIndex col) { m_CurrentRow = row; m_CurrentCol = col; } TIndex GetCurrentRow(void) const { return m_CurrentRow; } TIndex GetCurrentCol(void) const { return m_CurrentCol; } class CTableInfo; // Return cell, will add rows/columns if needed. // Throws exception if it is not left upper corner of cell // also sets current insertion point. CHTML_tc* Cell(TIndex row, TIndex column, ECellType type = eAnyCell); CHTML_tc* Cell(TIndex row, TIndex column, ECellType type, TIndex rowSpan, TIndex colSpan); CHTML_tc* HeaderCell(TIndex row, TIndex column) { return Cell(row, column, eHeaderCell); } CHTML_tc* DataCell(TIndex row, TIndex column) { return Cell(row, column, eDataCell); } CHTML_tc* NextCell(ECellType type = eAnyCell); CHTML_tc* NextHeaderCell(void) { return NextCell(eHeaderCell); } CHTML_tc* NextDataCell(void) { return NextCell(eDataCell); } CHTML_tc* NextRowCell(ECellType type = eAnyCell); CHTML_tc* NextRowHeaderCell(void) { return NextRowCell(eHeaderCell); } CHTML_tc* NextRowDataCell(void) { return NextRowCell(eDataCell); } // Check table contents for validaty, throws exception if invalid. void CheckTable(void) const; // Return width of table in columns. Should call CheckTable before. TIndex CalculateNumberOfColumns(void) const; TIndex CalculateNumberOfRows(void) const; // Return cell of insertion. CHTML_tc* InsertAt(TIndex row, TIndex column, CNCBINode* node); CHTML_tc* InsertAt(TIndex row, TIndex column, const string& text); CHTML_tc* InsertTextAt(TIndex row, TIndex column, const string& text); CHTML_tc* InsertNextCell(CNCBINode* node); CHTML_tc* InsertNextCell(const string& text); CHTML_tc* InsertNextRowCell(CNCBINode* node); CHTML_tc* InsertNextRowCell(const string& text); void ColumnWidth(CHTML_table*, TIndex column, const string & width); CHTML_table* SetCellSpacing(int spacing); CHTML_table* SetCellPadding(int padding); void ResetTableCache(void); virtual CNcbiOstream& PrintBegin(CNcbiOstream &, TMode mode); // If to print horizontal row separator (affects ePlainText mode only). enum ERowPlainSep { ePrintRowSep, // print eSkipRowSep // do not print }; // Set rows and cols separators (affects ePlainText mode only). void SetPlainSeparators(const string& col_left = kEmptyStr, const string& col_middle = " ", const string& col_right = kEmptyStr, const char row_sep_char = '-', ERowPlainSep is_row_sep = eSkipRowSep);protected: TIndex m_CurrentRow, m_CurrentCol; mutable auto_ptr<CHTML_table_Cache> m_Cache; CHTML_table_Cache& GetCache(void) const; friend class CHTML_table_Cache; friend class CHTML_tr; virtual void DoAppendChild(CNCBINode* node); void AppendRow(CHTML_tr* row); string m_ColSepL, m_ColSepM, m_ColSepR; char m_RowSepChar; ERowPlainSep m_IsRowSep;};// <form> tagclass NCBI_XHTML_EXPORT CHTML_form : public CHTMLElement{ typedef CHTMLElement CParent;public: enum EMethod { eGet, ePost, ePostData }; CHTML_form(void); CHTML_form(const string& url, EMethod method = eGet); CHTML_form(const string& url, CNCBINode* node, EMethod method = eGet); ~CHTML_form(void);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -