#include <CSHTMLElement.h>
Public Member Functions | |
virtual std::string | getType () |
HTMLElement (CSHTMLNode node) | |
~HTMLElement () | |
HTMLCursor | buildDisplay (HTMLCursor Cursor, CSGrafikElement *destination, int parentViewportWidth, std::string &title) |
int | getX () |
int | getY () |
int | getWidth () |
int | getHeight () |
void | clearPosition () |
void | clearCompiled () |
HTMLElement * | checkPostion (int x, int y) |
std::string | getText () |
int | getTagType () |
HTMLElement * | getAncestorType (int type) |
HTMLElement * | getChildType (int type, std::string attributName, std::string attributeValue) |
std::string | getAttributValue (std::string attributeName) |
int | getFirstYPostion () |
Static Public Member Functions | |
int | getColorFromString (std::string acolor) |
Static Public Attributes | |
const char * | CLASS = "HTMLElement" |
|
Definition at line 23 of file CSHTMLElement.cpp. References CSHTMLNode::firstChild(), CSHTMLNode::isEmpty(), CSHTMLNode::nextChild(), and setParent().
00024 { 00025 mNode = node; 00026 mParent = 0; 00027 mPositionsStored = false; 00028 CSHTMLNode child = mNode.firstChild(); 00029 while (!child.isEmpty()) 00030 { 00031 HTMLElement * nextChild = new HTMLElement(child); 00032 nextChild->setParent(this); 00033 mElements.push_back(nextChild); 00034 child = mNode.nextChild(); 00035 } 00036 00037 // we all listen to screen changes, since images must be updated! 00038 // the compilation information is corrupt, when some 00039 // instance have no compilation (all or nothing), (BODY TAG e.g. is not 00040 // sat anymore, if first tag is an image and only images are cleared!) 00041 00042 // if this is switched on, upon toggle screen -> the program 00043 // crashes -> unkown!!! 00044 //CSA SDLMain::getInstance()->addMessageListener(this, SDL_MESSAGE); 00045 } |
Here is the call graph for this function:
|
Definition at line 47 of file CSHTMLElement.cpp. References clearCompiled(), and clearPosition().
00048 { 00049 clearPosition(); 00050 clearCompiled(); 00051 HTMLElements::iterator iter = mElements.begin(); 00052 while (iter != mElements.end()) 00053 { 00054 HTMLElement *element = *iter; 00055 mElements.erase(iter); 00056 delete element; 00057 iter = mElements.begin(); 00058 } 00059 } |
Here is the call graph for this function:
|
Definition at line 236 of file CSHTMLElement.cpp. References CSHelper::convert(). Referenced by buildDisplay().
00237 { 00238 if (acolor.size()<= 0) 00239 { 00240 return -1; 00241 } 00242 int posStart = strstr(acolor.c_str(), "#") - acolor.c_str()+1; 00243 std::string v = acolor.substr(posStart, acolor.size()-posStart); 00244 int value = CSHelper::convert(v.c_str(), 16); 00245 return value; 00246 } |
Here is the call graph for this function:
|
Definition at line 136 of file CSHTMLElement.h. References CLASS.
00136 {return (std::string) CLASS;} |
|
Definition at line 257 of file CSHTMLElement.cpp. References CSGrafikElement::addElement(), CSHTMLNode::attributValue(), CSTextIcon::buildIcon(), CSPictureIcon::buildIcon(), FONT_STYLE_BOLD, FONT_STYLE_ITALIC, FONT_STYLE_UNDERLINE, getColorFromString(), CSLAF::getCurrentLAF(), CSLAF::getFont(), CSGrafikElement::getHeight(), CSFont::getHeight(), CSHTMLNode::getTag(), getTagType(), CSHTMLNode::getValue(), CSGrafikElement::getWidth(), CSFont::getWidth(), HTML_A, HTML_B, HTML_BODY, HTML_BR, HTML_DD, HTML_DT, HTML_H1, HTML_HTML, HTML_I, HTML_IMG, HTML_LI, HTML_OL, HTML_P, HTML_PRE, HTML_TITLE, HTML_UL, CSHTMLNode::isText(), HTMLCursor::mAddX, HTMLCursor::mBackgroundColor, HTMLCursor::mFont, HTMLCursor::mInBody, HTMLCursor::mInPre, HTMLCursor::mLinkColor, HTMLCursor::mListCounter, HTMLCursor::mPenColor, HTMLCursor::mStyle, HTMLCursor::mXPos, HTMLCursor::mXPosMax, HTMLCursor::mYPos, HTMLCursor::nextAdd, CSGrafikElement::setFont(), CSGrafikElement::setStyle(), CSLabel::setText(), CSGrafikElement::setTextColor(), and StringVector. Referenced by CSHTMLPanel::layoutSetupHTMLPanel().
00258 { 00259 bool goDeeper = true; 00260 std::string text = ""; 00261 std::string tag = mNode.getTag(); 00262 HTMLCursor returnCursor = cursor; 00263 00264 // TAG BEGIN 00265 // switch thru all known tags and 00266 // adjust cursor setting accordingly! 00267 switch (getTagType(mNode)) 00268 { 00269 case HTML_PRE: 00270 { 00271 CSLAF *laf = CSLAF::getCurrentLAF(); 00272 cursor.mInPre = true; 00273 00274 // PRE allways starts at a new line 00275 cursor.mXPos = 0; 00276 cursor.mXPos += cursor.mAddX; 00277 cursor.mYPos += cursor.nextAdd; 00278 cursor.nextAdd = cursor.mFont->getHeight(); 00279 cursor.mFont = laf->getFont("MonoSpaced"); // Mono spaced font! 00280 break; 00281 } 00282 case HTML_HTML: 00283 { 00284 break; 00285 } 00286 case HTML_BODY: 00287 { 00288 // if there are - rememeber the colors! 00289 std::string bgColor = mNode.attributValue("BGCOLOR"); 00290 std::string textColor = mNode.attributValue("TEXT"); 00291 std::string linkColor = mNode.attributValue("LINK"); 00292 00293 int t = getColorFromString(textColor); 00294 if (t != -1) cursor.mPenColor = t; 00295 00296 t = getColorFromString(bgColor); 00297 if (t != -1) cursor.mBackgroundColor = t; 00298 00299 t = getColorFromString(linkColor); 00300 if (t != -1) cursor.mLinkColor = t; 00301 00302 // only tags within body are displayed! 00303 cursor.mInBody = true; 00304 break; 00305 } 00306 case HTML_TITLE: 00307 { 00308 //quick Hack, since possible in Title there might be (stupid!!!) other tags! 00309 title = getChildrenAsText(); 00310 goDeeper = false; 00311 break; 00312 } 00313 case HTML_LI: 00314 { 00315 // list counter for <OL> - List get garbled when 00316 // Lists are used in lists - not fixed yet 00317 // (not even thought about it...) 00318 00319 // counter == -1 is an unordered list, 00320 // everything else is the counter for the ordered list 00321 if (cursor.mListCounter != -1) 00322 { 00323 // produce some text output as counters for the ordered list 00324 char helper[10]; 00325 cursor.mListCounter++; 00326 sprintf(helper, "%i. ", cursor.mListCounter); 00327 text = std::string(helper); 00328 } 00329 else 00330 { 00331 // nothing fancy for not ordered Lists, just an asterix 00332 text = std::string("* "); 00333 } 00334 } 00335 case HTML_DT: 00336 { 00337 cursor.mXPos = 0; 00338 cursor.mYPos += cursor.nextAdd; 00339 cursor.nextAdd = cursor.mFont->getHeight(); 00340 cursor.mXPos += cursor.mAddX; 00341 break; 00342 } 00343 case HTML_OL: 00344 { 00345 // start the ordered list counter at 0 00346 cursor.mListCounter = 0; 00347 } 00348 case HTML_UL: 00349 case HTML_DD: 00350 { 00351 // and do some indenting for the lists 00352 cursor.mAddX += 3*cursor.mFont->getWidth(" "); 00353 break; 00354 } 00355 00356 // well just the ol' carriage return 00357 case HTML_BR: 00358 // haven't done any real HR's yet 00359 case HTML_H1: 00360 { 00361 cursor.mXPos = 0; 00362 cursor.mXPos += cursor.mAddX; 00363 cursor.mYPos += cursor.nextAdd; 00364 cursor.nextAdd = cursor.mFont->getHeight(); 00365 break; 00366 } 00367 00368 // two lines might actually be to much - but what the heck 00369 // not done the whole attribute staff here 00370 case HTML_P: 00371 { 00372 cursor.mXPos = 0; 00373 cursor.mXPos += cursor.mAddX; 00374 cursor.mYPos += cursor.nextAdd; 00375 cursor.nextAdd = cursor.mFont->getHeight(); 00376 cursor.mYPos += cursor.nextAdd; 00377 break; 00378 } 00379 case HTML_A: 00380 { 00381 // just for show - the attributes are needed some other time! 00382 // std::string rawURL = mNode.attributValue("HREF"); 00383 // std::string formattedURL = formatURL(rawURL); 00384 // std::string ankerName = mNode.attributValue("NAME"); 00385 if (mNode.attributValue("HREF").size() != 0 ) 00386 { 00387 cursor.mStyle = cursor.mStyle | FONT_STYLE_UNDERLINE; 00388 cursor.mPenColor = cursor.mLinkColor; 00389 } 00390 00391 // for quicker finding of a possible Anker 00392 mX = cursor.mXPos; 00393 mY = cursor.mYPos; 00394 break; 00395 } 00396 case HTML_B: 00397 { 00398 cursor.mStyle = cursor.mStyle | FONT_STYLE_BOLD; 00399 break; 00400 } 00401 case HTML_I: 00402 { 00403 // some day I might use TTF - but until than this is just for the show 00404 cursor.mStyle = cursor.mStyle | FONT_STYLE_ITALIC; 00405 break; 00406 } 00407 case HTML_IMG: 00408 { 00409 // load a picture! 00410 cursor.mXPos = 0; 00411 cursor.mXPos += cursor.mAddX; 00412 std::string rawURL = mNode.attributValue("SRC"); 00413 std::string formattedURL = formatURL(rawURL); 00414 00415 // just to rememeber 00416 // cursor.mXPos is the position within the viewport 00417 // parentViewport->x is the position on screen of the viewport 00418 // cursor.mStartHorizontalDisplayAtPixel is the offset produced by scrolling withing the viewport 00419 int x = cursor.mXPos; 00420 int y = cursor.mYPos; 00421 00422 CSIcon *icon = CSPictureIcon::buildIcon(CSPictureDirectLoader::INSTANCE.load(formattedURL)); 00423 if (icon == 0) 00424 { 00425 text = std::string()+"[Image not found: "+formattedURL+"]"; 00426 icon = CSTextIcon::buildIcon(text); 00427 } 00428 if (icon != 0) 00429 { 00430 cursor.mXPos += icon->getWidth(); 00431 cursor.nextAdd = icon->getHeight(); 00432 if (cursor.mXPos > cursor.mXPosMax) 00433 { 00434 cursor.mXPosMax = cursor.mXPos; 00435 } 00436 00437 if (destination) 00438 { 00439 destination->addElement(icon, x, y); 00440 } 00441 else 00442 { 00443 delete icon; 00444 } 00445 } 00446 } 00447 } 00448 00449 // if node has text - get it 00450 if (mNode.isText()) 00451 { 00452 text = mNode.getValue(); 00453 } 00454 00455 // even none text Nodes can have "textuall" effects - see above 00456 00457 // display text with current cursor settings 00458 // (if in Body of html page) 00459 if (cursor.mInBody == true) 00460 { 00461 if (text.size() != 0) 00462 { 00463 // pre is bad... 00464 // we display (sort of) 00465 // every letter by itself - so we don't miss "carriage return" 00466 if (cursor.mInPre) 00467 { 00468 std::string textOut = ""; 00469 for (const char *pointerToText = text.c_str(); (*pointerToText);pointerToText++) 00470 { 00471 if (*pointerToText != '\n') 00472 { 00473 char letter[2]; 00474 letter[0] = *pointerToText; 00475 letter[1] = 0; 00476 textOut += letter; 00477 } 00478 else 00479 { 00480 // if there was a carriage return - display the collected letters 00481 if (destination) 00482 { 00483 int x = cursor.mXPos; 00484 int y = cursor.mYPos; 00485 00486 CSLabel *label = new CSLabel(); 00487 label->setFont(cursor.mFont); 00488 label->setStyle(cursor.mStyle); 00489 label->setTextColor(cursor.mPenColor); 00490 label->setText(textOut); 00491 destination->addElement(label, x, y); 00492 } 00493 // and more than one position as well 00494 if (!mPositionsStored) 00495 { 00496 addPostion(cursor.mXPos, cursor.mYPos, cursor.mFont->getWidth(textOut), cursor.mFont->getHeight()); 00497 } 00498 cursor.mXPos += cursor.mFont->getWidth(textOut); 00499 textOut = ""; 00500 if (cursor.mXPos > cursor.mXPosMax) 00501 { 00502 cursor.mXPosMax = cursor.mXPos; 00503 } 00504 00505 cursor.mXPos = 0; 00506 cursor.mXPos += cursor.mAddX; 00507 cursor.mYPos += cursor.nextAdd; 00508 cursor.nextAdd = cursor.mFont->getHeight(); 00509 } 00510 } 00511 00512 // done with the tag, but nor carriage return found 00513 // than display the collected letters without it... 00514 if (textOut.size() > 0) 00515 { 00516 if (destination) 00517 { 00518 int x = cursor.mXPos; 00519 int y = cursor.mYPos; 00520 CSLabel *label = new CSLabel(); 00521 label->setFont(cursor.mFont); 00522 label->setStyle(cursor.mStyle); 00523 label->setTextColor(cursor.mPenColor); 00524 label->setText(textOut); 00525 destination->addElement(label, x, y); 00526 } 00527 if (!mPositionsStored) 00528 { 00529 addPostion(cursor.mXPos, cursor.mYPos, cursor.mFont->getWidth(textOut), cursor.mFont->getHeight()); 00530 } 00531 cursor.mXPos += cursor.mFont->getWidth(textOut); 00532 textOut = ""; 00533 if (cursor.mXPos > cursor.mXPosMax) 00534 { 00535 cursor.mXPosMax = cursor.mXPos; 00536 } 00537 } 00538 } 00539 else 00540 { 00541 // Non Pre - displaying is easier now (sort of) 00542 // First build tokens for ech word 00543 // build lines that fill the space we have got as good as possible 00544 StringVector::iterator iter; 00545 StringVector *tokens = tokenifyText(text); 00546 int width = 0; 00547 // build a textline 00548 std::string line=""; 00549 00550 // go thru all tokens 00551 for (iter = tokens->begin(); iter != tokens->end();) 00552 { 00553 char *word = *iter; 00554 00555 width = cursor.mFont->getWidth(line+" "+word); 00556 // not wider than the viewport - keep on collecting 00557 if (cursor.mXPos + width < parentViewportWidth) 00558 { 00559 if (line.size()>0) 00560 { 00561 line = line +" "+ word; 00562 } 00563 else 00564 { 00565 line = line + word; 00566 } 00567 } 00568 else 00569 { 00570 // if wider than the viewport - display it an build up a 00571 // new line 00572 if (destination) 00573 { 00574 int x = cursor.mXPos; 00575 int y = cursor.mYPos; 00576 CSLabel *label = new CSLabel(); 00577 label->setFont(cursor.mFont); 00578 label->setStyle(cursor.mStyle); 00579 label->setTextColor(cursor.mPenColor); 00580 label->setText(line); 00581 destination->addElement(label, x, y); 00582 } 00583 if (!mPositionsStored) 00584 { 00585 addPostion(cursor.mXPos, cursor.mYPos, cursor.mFont->getWidth(line), cursor.mFont->getHeight()); 00586 } 00587 cursor.mXPos += cursor.mFont->getWidth(line); 00588 if (cursor.mXPos > cursor.mXPosMax) 00589 { 00590 cursor.mXPosMax = cursor.mXPos; 00591 } 00592 cursor.mXPos = 0; 00593 cursor.mXPos += cursor.mAddX; 00594 cursor.mYPos += cursor.nextAdd; 00595 cursor.nextAdd = cursor.mFont->getHeight(); 00596 line = word; 00597 } 00598 iter++; 00599 } 00600 00601 // done, but line was not full 00602 // so we display what we have got... 00603 if (destination) 00604 { 00605 int x = cursor.mXPos; 00606 int y = cursor.mYPos; 00607 CSLabel *label = new CSLabel(); 00608 label->setFont(cursor.mFont); 00609 label->setStyle(cursor.mStyle); 00610 label->setTextColor(cursor.mPenColor); 00611 label->setText(line); 00612 destination->addElement(label, x, y); 00613 } 00614 if (!mPositionsStored) 00615 { 00616 addPostion(cursor.mXPos, cursor.mYPos, cursor.mFont->getWidth(line), cursor.mFont->getHeight()); 00617 } 00618 if (line.size()>0) 00619 { 00620 line = line + " "; 00621 } 00622 cursor.mXPos += cursor.mFont->getWidth(line); 00623 if (cursor.mXPos > cursor.mXPosMax) 00624 { 00625 cursor.mXPosMax = cursor.mXPos; 00626 } 00627 00628 for (iter = tokens->begin(); iter != tokens->end();iter++) 00629 { 00630 char *word = *iter; 00631 free(word); 00632 } 00633 tokens->clear(); 00634 delete (tokens); 00635 tokens = 0; 00636 } 00637 } 00638 } 00639 00640 // was the tag one that can have other tags inside? (nearly all!) 00641 // than go deeper (recursively) 00642 if (goDeeper == true) 00643 { 00644 HTMLElements::iterator iter; 00645 for (iter = mElements.begin(); iter != mElements.end(); iter++) 00646 { 00647 HTMLElement *element = *iter; 00648 cursor = element->buildDisplay(cursor, destination, parentViewportWidth, title); 00649 } 00650 } 00651 00652 // at the end of a Tag "reset" the cursor to its origin 00653 // (only position information is kept!) 00654 returnCursor.mYPos = cursor.mYPos; 00655 returnCursor.mXPos = cursor.mXPos; 00656 returnCursor.nextAdd = cursor.nextAdd; 00657 returnCursor.mXPosMax = cursor.mXPosMax; 00658 00659 // for more than one list(cascading), the list counting is not correct! 00660 // can at the moment not be bothered to correct it... 00661 returnCursor.mListCounter = cursor.mListCounter; 00662 mPositionsStored = true; 00663 00664 return returnCursor; 00665 } |
Here is the call graph for this function:
|
Definition at line 141 of file CSHTMLElement.h.
00141 {return mX;}
|
|
Definition at line 142 of file CSHTMLElement.h.
00142 {return mY;}
|
|
Definition at line 143 of file CSHTMLElement.h.
00143 {return mWidth;}
|
|
Definition at line 144 of file CSHTMLElement.h.
00144 {return mHeight;}
|
|
Definition at line 61 of file CSHTMLElement.cpp. Referenced by ~HTMLElement().
00062 { 00063 HTMLElements::iterator eiter; 00064 for (eiter = mElements.begin(); eiter != mElements.end(); eiter++) 00065 { 00066 HTMLElement *element = *eiter; 00067 element->clearPosition(); 00068 } 00069 00070 Positions::iterator iter = mPositions.begin(); 00071 while (iter != mPositions.end()) 00072 { 00073 SDL_Rect *rect = *iter; 00074 mPositions.erase(iter); 00075 delete (rect); 00076 iter = mPositions.begin(); 00077 } 00078 mPositionsStored = false; 00079 } |
|
Definition at line 81 of file CSHTMLElement.cpp. Referenced by ~HTMLElement().
00082 { 00083 } |
|
Definition at line 682 of file CSHTMLElement.cpp.
00683 { 00684 Positions::iterator iter = mPositions.begin(); 00685 while (iter != mPositions.end()) 00686 { 00687 SDL_Rect *rect = *iter; 00688 if (((x > rect->x) && (x < rect->x + rect->w)) && ((y > rect->y) && (y < rect->y + rect->h))) 00689 { 00690 return this; 00691 } 00692 iter++; 00693 } 00694 HTMLElements::iterator eiter; 00695 for (eiter = mElements.begin(); eiter != mElements.end(); eiter++) 00696 { 00697 HTMLElement *checked = (*eiter)->checkPostion(x, y); 00698 if (checked != 0) 00699 { 00700 return checked; 00701 } 00702 } 00703 return 0; 00704 } |
|
Definition at line 148 of file CSHTMLElement.h. References CSHTMLNode::getValue(), and CSHTMLNode::isText().
|
Here is the call graph for this function:
|
Definition at line 99 of file CSHTMLElement.cpp. Referenced by buildDisplay().
00100 { 00101 return getTagType(mNode); 00102 } |
|
Definition at line 85 of file CSHTMLElement.cpp. References getParent(), and getTagType(). Referenced by CSHTMLPanel::reactOnMessageHTMLPanel().
00086 { 00087 HTMLElement *parent = getParent(); 00088 while (parent) 00089 { 00090 if (parent->getTagType() == type) 00091 { 00092 return parent; 00093 } 00094 parent = parent->getParent(); 00095 } 00096 return 0; 00097 } |
Here is the call graph for this function:
|
Definition at line 195 of file CSHTMLElement.cpp. References getAttributValue(), and getTagType().
00196 { 00197 HTMLElements::iterator iter; 00198 for (iter = mElements.begin(); iter != mElements.end(); iter++) 00199 { 00200 HTMLElement *element = *iter; 00201 if (element->getTagType() == type) 00202 { 00203 if ((attributeName.size() == 0) || (attributeValue.size == 0)) 00204 { 00205 return element; 00206 } 00207 std::string elementAttributeValue = element->getAttributValue(attributeName); 00208 if (elementAttributeValue.compare(attributeValue) == 0) 00209 { 00210 return element; 00211 } 00212 } 00213 HTMLElement *childResult = element->getChildType(type, attributeName, attributeValue); 00214 if (childResult) 00215 { 00216 return childResult; 00217 } 00218 } 00219 return 0; 00220 } |
Here is the call graph for this function:
|
Definition at line 229 of file CSHTMLElement.cpp. References CSHTMLNode::attributValue(). Referenced by getChildType(), and CSHTMLPanel::reactOnMessageHTMLPanel().
00230 { 00231 return mNode.attributValue(attributeName); 00232 } |
Here is the call graph for this function:
|
Definition at line 708 of file CSHTMLElement.cpp.
00709 {
00710 return mY;
00711 }
|
|
Definition at line 21 of file CSHTMLElement.cpp. Referenced by getType(). |