// HTML_Element.cpp: implementation of the HTML_Element class. // ////////////////////////////////////////////////////////////////////// #include "HTML_all.h" #include "HTML_Element.h" #include "HTML_Table.h" #include "HTML_Font.h" #include "HTML_Form.h" #include "HTML_Select.h" #include "HTML_Input.h" #include "HTML_TextArea.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// HTML_Element::HTML_Element() { } HTML_Element::~HTML_Element() { clearList(); //delete all dependencies } string HTML_Element::getText() { return(text); } HTML_Element* HTML_Element::setText(char * str) { text = str; convertToHTML(text); return(this); } HTML_Element* HTML_Element::setRawText(char * str) { text = str; return(this); } HTML_Tag* HTML_Element::newTag(char * tagname) { HTML_Tag* t; t = new HTML_Tag(tagname); insert(t); return(t); } HTML_Element* HTML_Element::write(char * str) { HTML_Element* line; line = new HTML_Element(); line->setText(str); insert(line); return(this); } HTML_Element* HTML_Element::writeRaw(char * str) { HTML_Element* line; line = new HTML_Element(); line->setRawText(str); insert(line); return(this); } HTML_Element* HTML_Element::overwrite(char * str) { HTML_Element* line; if(objects.size() == 0) { write(str); } else { line = (HTML_Element*)objects.back(); line->setText(str); } return(this); } HTML_Element* HTML_Element::write(const char * str) { write((char*)str); return(this); } string& HTML_Element::printString() { buffer = ""; //clear buffer if(objects.size() == 0) { //if no nested objects print just text buffer = getText(); } else { //if there is nested objects print all of them printStringNested(); } buffer.append("\n"); return(buffer); } HTML_Table* HTML_Element::newTable() { HTML_Table* t; t = new HTML_Table; insert(t); return(t); } HTML_Element* HTML_Element::printStringNested() { HTML_ObjectListIterator i; i = objects.begin(); while(i != objects.end()) { buffer.append((*i)->printString()); i++; } return(this); } HTML_Element* HTML_Element::printOptions() { //no options by default return(this); } HTML_Font* HTML_Element::newFont() { HTML_Font* t; t = new HTML_Font; insert(t); return(t); } HTML_Tag* HTML_Element::bold() { return(newTag("STRONG")); } HTML_Tag* HTML_Element::italic() { return(newTag("I")); } HTML_Element* HTML_Element::br() { return(newTag("BR")->setMatched(false)); } HTML_Form* HTML_Element::newForm() { HTML_Form* t; t = new HTML_Form; insert(t); return(t); } HTML_Select* HTML_Element::newSelect() { HTML_Select* t; t = new HTML_Select; insert(t); return(t); } HTML_Input* HTML_Element::newInput(char* x) { HTML_Input* t; t = new HTML_Input; t->setType(x); insert(t); return(t); } HTML_TextArea* HTML_Element::newTextArea() { HTML_TextArea* t; t = new HTML_TextArea; insert(t); return(t); } HTML_Element* HTML_Element::clearList() { HTML_ObjectList::iterator i; if(objects.size() != 0) { i = objects.begin(); while(i != objects.end()) { delete(*i); i++; } objects.clear(); } return(this); } HTML_Element* HTML_Element::insert(HTML_Element * obj) { objects.push_back(obj); return(this); }