00001 #ifdef WIN32
00002 #pragma warning(disable : 4786 )
00003 #endif
00004
00005 #include "CSGrafikElement.h"
00006 #include "CSDesktop.h"
00007 #include "CSWindow.h"
00008 #include "CSBorder.h"
00009 #include "CSFont.h"
00010 #include "CSArea.h"
00011 #include "CSLayoutManager.h"
00012
00013 const char *CSGrafikElement::CLASS = "CSGrafikElement";
00014
00015 CSGrafikElement::CSGrafikElement(int height, int width)
00016 {
00017 static char *functionName="CSGrafikElement";
00018 LOG_ENTER
00019 CSLAF *laf = CSLAF::getCurrentLAF();
00020 CSLAF::addElement(this);
00021 init(height, width);
00022 addMessageListener(this, GUI_MESSAGE);
00023 mTooltipText = "";
00024 LOG_EXIT
00025 }
00026
00027
00028
00029
00030 CSGrafikElement::~CSGrafikElement(void)
00031 {
00032 static char *functionName="~CSGrafikElement";
00033 LOG_ENTER
00034 removeMessageListener(this);
00035 CSGrafikElement *parent = getParent();
00036 if (parent)
00037 {
00038 parent->removeMainElement(this);
00039 }
00040
00041
00042
00043
00044
00045
00046 if (mMainElement != this)
00047 {
00048 CSGrafikElements::iterator iter = mElements.begin();
00049 while (iter != mElements.end())
00050 {
00051 CSGrafikElement *element = *iter;
00052 if (element == mMainElement)
00053 {
00054 mElements.erase(iter);
00055 delete (element);
00056 break;
00057 }
00058 iter++;
00059 }
00060 mMainElement = this;
00061 }
00062
00063 CSGrafikElements::iterator iter = mElements.begin();
00064 while (iter != mElements.end())
00065 {
00066 CSGrafikElement *element = *iter;
00067 mElements.erase(iter);
00068 delete (element);
00069 iter = mElements.begin();
00070 }
00071 if (mBorder)
00072 {
00073 delete mBorder;
00074 mBorder = 0;
00075 }
00076 if (mArea)
00077 {
00078 delete mArea;
00079 mArea = 0;
00080 }
00081 if (mLayoutManager != 0)
00082 {
00083 delete mLayoutManager;
00084 mLayoutManager = 0;
00085 }
00086 CSLAF::removeElement(this);
00087
00088 LOG_EXIT
00089 }
00090
00091 void CSGrafikElement::init(int height, int width)
00092 {
00093 static char *functionName="init";
00094 LOG_ENTER
00095 mMainElement = this;
00096 CSLAF *laf = CSLAF::getCurrentLAF();
00097 MESSAGE_FOCUS_GAINED.setSubtype(FOCUS_GAINED_MESSAGE);
00098 MESSAGE_FOCUS_LOST.setSubtype(FOCUS_LOST_MESSAGE);
00099 MESSAGE_KEY_PRESSED.setSubtype(KEY_PRESSED_MESSAGE);
00100 MESSAGE_KEY_RELEASED.setSubtype(KEY_RELEASED_MESSAGE);
00101 MESSAGE_MOUSE_PRESSED.setSubtype(MOUSE_BUTTON_PRESSED_MESSAGE);
00102 MESSAGE_MOUSE_RELEASED.setSubtype(MOUSE_BUTTON_RELEASED_MESSAGE);
00103 MESSAGE_MOUSE_MOTION.setSubtype(MOUSE_MOTION_MESSAGE);
00104 MESSAGE_MOUSE_MOTION_LOST.setSubtype(MOUSE_MOTION_LOST_MESSAGE);
00105 mFrontElement = false;
00106 mBorderState = BORDER_STATE_DEFAULT;
00107 mActionId = 0;
00108 mParent = 0;
00109 mFont = 0;
00110 mBorder = 0;
00111 mArea = 0;
00112 mLayoutManager = 0;
00113 mLayoutChanged = true;
00114 setLayoutManager(new CSLayoutManagerXY());
00115 mX = 0;
00116 mY = 0;
00117 mHeight = height;
00118 mWidth = width;
00119 mMinWidth = 0;
00120 mMinHeight = 0;
00121 if (mHeight < getBorder()->getTotalHeight() + mInset.getTotalHeight())
00122 {
00123 mHeight = getBorder()->getTotalHeight() + mInset.getTotalHeight();
00124 }
00125 if (mWidth < getBorder()->getTotalWidth() + mInset.getTotalWidth())
00126 {
00127 mWidth = getBorder()->getTotalWidth() + mInset.getTotalWidth();
00128 }
00129
00130 mViewportX = getBorder()->getSizeWest() + mInset.getSizeWest();
00131 mViewportY = getBorder()->getSizeNorth() + mInset.getSizeNorth();
00132 mViewportHeight = getHeight() - getBorder()->getTotalHeight() - mInset.getTotalHeight();
00133 mViewportWidth = getWidth() - getBorder()->getTotalWidth() - mInset.getTotalWidth();
00134
00135 if (mViewportHeight < 0) mViewportHeight = 0;
00136 if (mViewportWidth < 0) mViewportWidth = 0;
00137
00138 mViewportOffsetX = 0;
00139 mViewportOffsetY = 0;
00140
00141 mStyle = FONT_STYLE_NONE;
00142 mEnabled = true;
00143 mActivated = false;
00144 mActive = false;
00145 mVisible = true;
00146 mModal = false;
00147 mFocused = false;
00148 mFocusable = true;
00149 mHeightSet = false;
00150 mWidthSet = false;
00151
00152 mBackGroundColorSet = false;
00153 mTextColorSet = false;
00154 mHorizontalElementSpacingSet = false;
00155 mVerticalElementSpacingSet = false;
00156
00157 mBackgroundColor = laf->getBackgroundColorDisabled(getGUIType());
00158 mTextColor = laf->getTextColorDisabled(getGUIType());
00159 mHorizontalElementSpacing = laf->getHorizontalElementSpacing(getGUIType());
00160 mVerticalElementSpacing = laf->getVerticalElementSpacing(getGUIType());
00161 cursorDefault();
00162 layoutSetup();
00163 LOG_EXIT
00164 }
00165
00166
00167 void CSGrafikElement::setPosition(int x, int y)
00168 {
00169 static char *functionName="setPosition";
00170 if ((mX != x) || (mY != y))
00171 {
00172 if (mParent)
00173 {
00174
00175 if (mParent->getLayoutManager()->getType().compare(CSLayoutManagerXY.CLASS) != 0)
00176 {
00177 return;
00178 }
00179 }
00180
00181 mX = x;
00182 mY = y;
00183 getLayoutDataInternal()->setX(mX);
00184 getLayoutDataInternal()->setY(mY);
00185 layoutChanged();
00186 }
00187 }
00188
00189 void CSGrafikElement::setHeight(int h)
00190 {
00191 static char *functionName="setHeight";
00192 LOG_ENTER
00193 if (h == -1)
00194 {
00195 mHeightSet = false;
00196 }
00197 else
00198 {
00199 if (h < mMinHeight)
00200 {
00201 h = mMinHeight;
00202 }
00203 if (mHeight != h)
00204 {
00205 mHeightSet = true;
00206 mHeight = h;
00207 layoutChanged(true);
00208 }
00209 }
00210 LOG_EXIT
00211 }
00212
00213 void CSGrafikElement::setWidth(int w)
00214 {
00215 static char *functionName="setWidth";
00216 LOG_ENTER
00217 if (w == -1)
00218 {
00219 mWidthSet = false;
00220 }
00221 else
00222 {
00223 if (w < mMinWidth)
00224 w = mMinWidth;
00225 if (mWidth != w)
00226 {
00227 mWidthSet = true;
00228 mWidth = w;
00229 layoutChanged(true);
00230 }
00231 }
00232 LOG_EXIT
00233 }
00234
00235 void CSGrafikElement::paintBorder(SDL_Surface *destination, SDL_Rect *parentArea)
00236 {
00237 SDL_Rect area = getElementArea();
00238 area.x += parentArea->x;
00239 area.y += parentArea->y;
00240 CSBorder *border = getBorder();
00241 if (border)
00242 {
00243 border->paint(destination, &area);
00244 }
00245 }
00246
00247 void CSGrafikElement::paintAreaStandard(SDL_Surface *destination, SDL_Rect *parentArea)
00248 {
00249 SDL_Rect elementArea = getElementArea();
00250 elementArea.x += parentArea->x;
00251 elementArea.y += parentArea->y;
00252 CSArea *area = getArea();
00253 if (area)
00254 {
00255 area->setColor(COLOR(destination, getBackgroundColor()));
00256 area->paint(destination, &elementArea);
00257 }
00258 }
00259
00260
00261
00262 void CSGrafikElement::paintChildren(SDL_Surface *destination, SDL_Rect *parentViewport)
00263 {
00264 static char *functionName="paintChildren";
00265 CSGrafikElement *modalDetected = 0;
00266 SDL_Rect saveRect;
00267
00268 SDL_GetClipRect(destination, &saveRect);
00269 SDL_Rect thisViewportArea;
00270 SDL_Rect thisViewportAreaCopy;
00271
00272 thisViewportArea.x = parentViewport->x + mViewportX + mX;
00273 thisViewportArea.y = parentViewport->y + mViewportY + mY;
00274 thisViewportArea.h = mViewportHeight;
00275 thisViewportArea.w = mViewportWidth;
00276 thisViewportAreaCopy = thisViewportArea;
00277
00278 int offsetX = 0;
00279 int offsetY = 0;
00280 getViewportOffset(offsetX, offsetY);
00281
00282 thisViewportArea.x -= offsetX;
00283 thisViewportArea.y -= offsetY;
00284
00285
00286 SDLMain::adjustClipping(thisViewportAreaCopy, saveRect);
00287 SDL_SetClipRect(destination, &thisViewportAreaCopy);
00288
00289 CSGrafikElements::iterator iter = mElements.begin();
00290 while (iter != mElements.end())
00291 {
00292 CSGrafikElement *element = (*iter);
00293 if (element->getVisible())
00294 {
00295 if (!element->getModal())
00296 {
00297 element->paintArea(destination, &thisViewportArea);
00298 element->paint(destination, &thisViewportArea);
00299 element->paintBorder(destination, &thisViewportArea);
00300 }
00301 else
00302 {
00303 modalDetected = *iter;
00304 }
00305 }
00306 iter++;
00307 }
00308
00309 SDL_SetClipRect(destination, &saveRect);
00310
00311 if (modalDetected)
00312 {
00313 if (getDesktop())
00314 {
00315 getDesktop()->runModalDesktop(modalDetected, destination);
00316 }
00317 }
00318
00319 }
00320
00321 void CSGrafikElement::toFront(CSGrafikElement *element)
00322 {
00323 CSGrafikElements::iterator iter = mElements.begin();
00324 bool elementFound = false;
00325 while (iter != mElements.end())
00326 {
00327 if ((*iter) == element)
00328 {
00329 mElements.erase(iter);
00330 elementFound = true;
00331 break;
00332 }
00333 iter++;
00334 }
00335 if (elementFound == true)
00336 {
00337 mElements.push_back(element);
00338 }
00339 }
00340
00341 void CSGrafikElement::setParent(CSGrafikElement *parent)
00342 {
00343 static char *functionName="setParent";
00344 LOG_ENTER
00345 mParent = parent;
00346 LOG_EXIT
00347 }
00348
00349
00350
00351
00352 void CSGrafikElement::line(SDL_Surface *destination, SDL_Rect *parentViewport, int x1, int y1, int x2, int y2, Uint32 color)
00353 {
00354 static char *functionName="line";
00355
00356 SDLMain::line(destination, parentViewport->x + x1, parentViewport->y + y1, parentViewport->x + x2, parentViewport->y + y2, (color<<8)+255);
00357 }
00358
00359
00360
00361
00362 void CSGrafikElement::putString(SDL_Surface *destination, SDL_Rect *parentViewport, int x1, int y1, const std::string &string)
00363 {
00364 static char *functionName="putString";
00365 getFont()->putString(destination, parentViewport->x + x1, parentViewport->y + y1, mTextColor ,string, mStyle);
00366 }
00367
00368
00369
00370
00371 void CSGrafikElement::putString(SDL_Surface *destination, SDL_Rect *parentViewport, int x1, int y1, int color, const std::string &string)
00372 {
00373 static char *functionName="putString";
00374 getFont()->putString(destination, parentViewport->x + x1, parentViewport->y + y1, color, string, mStyle);
00375 }
00376
00377
00378 bool CSGrafikElement::isIn(int x, int y, SDL_Rect *parentElementArea)
00379 {
00380 static char *functionName="isIn";
00381 if (!getVisible())
00382 {
00383 return false;
00384 }
00385 int startX, startY;
00386 int endX, endY;
00387
00388
00389
00390
00391 if (parentElementArea)
00392 {
00393 startX = parentElementArea->x+mX;
00394 startY = parentElementArea->y+mY;
00395 endY = mHeight + parentElementArea->y+mY;
00396 endX = mWidth + parentElementArea->x+mX;
00397 }
00398 else
00399 {
00400 startX = mX;
00401 startY = mY;
00402 endY = mHeight + mY;
00403 endX = mWidth + mX;
00404 }
00405
00406
00407 if ((x>=startX) && (x<endX) && (y>=startY) && (y<endY))
00408 {
00409 bool b = !isTransparent(x, y, parentElementArea);
00410 return b;
00411 }
00412
00413 return false;
00414 }
00415
00416
00417
00418 CSGrafikElement *CSGrafikElement::getElement(int x, int y, SDL_Rect *parentElementArea, int &receiverX, int &receiverY)
00419 {
00420 static char *functionName="getElement";
00421 CSGrafikElements::reverse_iterator riter = mElements.rbegin();
00422 SDL_Rect thisElementArea = mElementArea;
00423 thisElementArea.x += parentElementArea->x;
00424 thisElementArea.y += parentElementArea->y;
00425 SDL_Rect thisElementAreaViewported = thisElementArea;
00426
00427
00428 int offsetX = 0;
00429 int offsetY = 0;
00430 getViewportOffset(offsetX, offsetY);
00431
00432 thisElementAreaViewported.x += mViewportX - offsetX;
00433 thisElementAreaViewported.y += mViewportY - offsetY;
00434
00435 riter = mElements.rbegin();
00436 while (riter != mElements.rend())
00437 {
00438 CSGrafikElement *element = (*riter);
00439 bool isInElement;
00440 isInElement = element->isIn(x, y, &thisElementAreaViewported);
00441 if (isInElement)
00442 {
00443 CSGrafikElement *element = (*riter)->getElement(x, y, &thisElementAreaViewported, receiverX, receiverY);
00444 return element;
00445 }
00446 riter++;
00447 }
00448
00449 receiverX = x - thisElementArea.x;
00450 receiverY = y - thisElementArea.y;
00451
00452 getFont()->setSolid(true);
00453 std::string type = this->getType();
00454 char str[100];
00455 if (type.compare(CSWindow::CLASS) == 0)
00456 {
00457 getFont()->putString(SDLMain::getScreen(), 0, 405, "Window searched!");
00458 }
00459 sprintf(str, "%i, %i (x, y) ",x,y);
00460 getFont()->putString(SDLMain::getScreen(), 0, 420, str);
00461 sprintf(str, "%i, %i (px, py) ",parentElementArea->x,parentElementArea->y);
00462 getFont()->putString(SDLMain::getScreen(), 0, 435, str);
00463 sprintf(str, "%i, %i (ax, ay) ",thisElementArea.x,thisElementArea.y);
00464 getFont()->putString(SDLMain::getScreen(), 0, 450, str);
00465 getFont()->putString(SDLMain::getScreen(), 0, 465,this->getType());
00466
00467 return this;
00468 }
00469
00470 void CSGrafikElement::setFocusable(bool b)
00471 {
00472 static char *functionName="setFocusable";
00473 mFocusable = b;
00474
00475 CSGrafikElements::iterator iter = mElements.begin();
00476 while (iter != mElements.end())
00477 {
00478 CSGrafikElement *test = *iter;
00479 test->setFocusable(b);
00480 iter++;
00481 }
00482 }
00483
00484 void CSGrafikElement::cursorSizing()
00485 {
00486 mCursorType = MOUSE_CURSOR_TYPE_SIZING;
00487 }
00488
00489 void CSGrafikElement::cursorDefault()
00490 {
00491 mCursorType = MOUSE_CURSOR_TYPE_DEFAULT;
00492 }
00493
00494 CSMouseCursor *CSGrafikElement::getCursor()
00495 {
00496 CSLAF *laf = CSLAF::getCurrentLAF();
00497 if (mCursorType == MOUSE_CURSOR_TYPE_SIZING)
00498 {
00499 return laf->getMouseCursor(LAF_MOUSE_CURSOR_SIZING_DOWN_RIGHT);
00500 }
00501
00502 return laf->getMouseCursor(LAF_MOUSE_CURSOR_DEFAULT);
00503 }
00504
00505 int CSGrafikElement::getElementMaxX()
00506 {
00507 int maxX = 0;
00508 CSGrafikElements::iterator iter = mElements.begin();
00509 while (iter != mElements.end())
00510 {
00511 CSGrafikElement *test = *iter;
00512 int x = test->getX() + test->getWidth();
00513 if (x > maxX)
00514 {
00515 maxX = x;
00516 }
00517 iter++;
00518 }
00519 return maxX;
00520 }
00521
00522 int CSGrafikElement::getElementMaxY()
00523 {
00524 int maxY = 0;
00525 CSGrafikElements::iterator iter = mElements.begin();
00526 while (iter != mElements.end())
00527 {
00528 CSGrafikElement *test = *iter;
00529 int y = test->getY() + test->getHeight();
00530 if (y > maxY)
00531 {
00532 maxY = y;
00533 }
00534 iter++;
00535 }
00536 return maxY;
00537 }
00538
00539 CSWindow *CSGrafikElement::getParentWindow(void)
00540 {
00541 static char *functionName="getParentWindow";
00542 CSGrafikElement *parent = this;
00543 while (parent != 0)
00544 {
00545 std::string type = parent->getType();
00546 if (type.compare(CSWindow::CLASS) == 0)
00547 {
00548 return (CSWindow *) parent;
00549 }
00550 parent = parent->getParent();
00551 }
00552
00553 return 0;
00554 }
00555
00556 CSDesktop *CSGrafikElement::getDesktop(void)
00557 {
00558 static char *functionName="getDesktop";
00559 CSGrafikElement *parent = this;
00560 while (parent != 0)
00561 {
00562 std::string type = parent->getType();
00563 if (type.compare(CSDesktop::CLASS) == 0)
00564 {
00565 return (CSDesktop *) parent;
00566 }
00567 parent = parent->getParent();
00568 }
00569 return 0;
00570 }
00571
00572 void CSGrafikElement::translateToDesktop(int &x, int &y)
00573 {
00574 static char *functionName="translateToDesktop";
00575 CSGrafikElement *parent = this;
00576 int offsetX = 0;
00577 int offsetY = 0;
00578 getViewportOffset(offsetX, offsetY);
00579 x = x - offsetX;
00580 y = y - offsetY;
00581 while (parent != 0)
00582 {
00583 std::string type = parent->getType();
00584 if (type.compare(CSDesktop::CLASS) == 0)
00585 {
00586 break;
00587 }
00588 x = x + parent->getX();
00589 y = y + parent->getY();
00590 x = x + parent->getParent()->getViewportX();
00591 y = y + parent->getParent()->getViewportY();
00592
00593 parent->getViewportOffset(offsetX, offsetY);
00594 x = x - offsetX;
00595 y = y - offsetY;
00596
00597 parent = parent->getParent();
00598 }
00599 }
00600
00601
00602 bool CSGrafikElement::isChild(CSGrafikElement *element)
00603 {
00604 static char *functionName="isChild";
00605 while (element != 0)
00606 {
00607 if (element == this)
00608 {
00609 return true;
00610 }
00611 element = element->getParent();
00612 }
00613 return false;
00614 }
00615
00616
00617
00618 void CSGrafikElement::lafChanged(int id)
00619 {
00620 if (mCurrentLAFId != id)
00621 {
00622 CSGrafikElements::iterator iter = mElements.begin();
00623 while (iter != mElements.end())
00624 {
00625 (*iter)->lafChanged(id);
00626 iter++;
00627 }
00628 rebuildElement();
00629 layoutChanged();
00630 mCurrentLAFId = id;
00631 }
00632 }
00633
00634
00635
00636 CSFont *CSGrafikElement::getFont()
00637 {
00638 if (mFont)
00639 {
00640 return mFont;
00641 }
00642 return CSLAF::getCurrentLAF()->getFont(getGUIType());
00643 }
00644
00645
00646
00647
00648
00649
00650
00651
00652 void CSGrafikElement::setArea(CSArea *area, bool deleteOldArea)
00653 {
00654 if (deleteOldArea)
00655 {
00656 if (mArea)
00657 {
00658 delete mArea;
00659 mArea = 0;
00660 }
00661 }
00662 mArea = area;
00663 }
00664
00665 CSArea *CSGrafikElement::getArea()
00666 {
00667 if (!mArea)
00668 {
00669 return CSLAF::getCurrentLAF()->getArea(getGUIType());
00670 }
00671 return mArea;
00672 }
00673
00674
00675
00676
00677
00678
00679 void CSGrafikElement::setBorder(CSBorder *border, bool deleteOldBorder)
00680 {
00681 if (deleteOldBorder)
00682 {
00683 if (mBorder)
00684 {
00685 delete mBorder;
00686 mBorder = 0;
00687 }
00688 }
00689 mBorder = border;
00690 layoutChanged();
00691 }
00692
00693 CSBorder *CSGrafikElement::getBorder()
00694 {
00695 if (!mBorder)
00696 {
00697 return CSLAF::getCurrentLAF()->getBorder(getGUIType(), mBorderState);
00698 }
00699 return mBorder;
00700 }
00701
00702 int CSGrafikElement::getBackgroundColor()
00703 {
00704 if (mBackGroundColorSet == true)
00705 {
00706 return mBackgroundColor;
00707 }
00708 if (getEnabled())
00709 {
00710 int color = -1;
00711 CSGrafikElement * element = this;
00712 while ((color == -1) && (element != 0))
00713 {
00714 color = CSLAF::getCurrentLAF()->getBackgroundColorEnabled(element->getGUIType());
00715 if (color != -1)
00716 {
00717 return color;
00718 }
00719 element = element->getParent();
00720 }
00721 return 255*256*256+255;
00722 }
00723 int color = -1;
00724 CSGrafikElement * element = this;
00725 while ((color == -1) && (element != 0))
00726 {
00727 color = CSLAF::getCurrentLAF()->getBackgroundColorDisabled(element->getGUIType());
00728 if (color != -1)
00729 {
00730 return color;
00731 }
00732 element = element->getParent();
00733 }
00734 return 255*256*256+255;
00735 }
00736
00737 void CSGrafikElement::setBackgroundColor(int backgroundColor)
00738 {
00739 mBackGroundColorSet = true;
00740 mBackgroundColor = backgroundColor;
00741 }
00742
00743 int CSGrafikElement::getTextColor()
00744 {
00745 if (mTextColorSet == true)
00746 {
00747 return mTextColor;
00748 }
00749 if (getEnabled())
00750 {
00751 int color = -1;
00752 CSGrafikElement * element = this;
00753 while ((color == -1) && (element != 0))
00754 {
00755 color = CSLAF::getCurrentLAF()->getTextColorEnabled(element->getGUIType());
00756 if (color != -1)
00757 {
00758 return color;
00759 }
00760 element = element->getParent();
00761 }
00762 return 255*256*256+255;
00763 }
00764 int color = -1;
00765 CSGrafikElement * element = this;
00766 while ((color == -1) && (element != 0))
00767 {
00768 color = CSLAF::getCurrentLAF()->getTextColorDisabled(element->getGUIType());
00769 if (color != -1)
00770 {
00771 return color;
00772 }
00773 element = element->getParent();
00774 }
00775 return 255*256*256+255;
00776 }
00777
00778 void CSGrafikElement::setTextColor(int textColor)
00779 {
00780 mTextColorSet = true;
00781 mTextColor = textColor;
00782 }
00783
00784 int CSGrafikElement::getVerticalElementSpacing()
00785 {
00786 if (mVerticalElementSpacingSet == true)
00787 {
00788 return mVerticalElementSpacing;
00789 }
00790 return CSLAF::getCurrentLAF()->getVerticalElementSpacing(getGUIType());
00791 }
00792
00793 void CSGrafikElement::setVerticalElementSpacing(int verticalElementSpacing)
00794 {
00795 mVerticalElementSpacingSet = true;
00796 mVerticalElementSpacing = verticalElementSpacing;
00797 layoutChanged();
00798 }
00799
00800 int CSGrafikElement::getHorizontalElementSpacing()
00801 {
00802 if (mHorizontalElementSpacingSet == true)
00803 {
00804 return mHorizontalElementSpacing;
00805 }
00806 return CSLAF::getCurrentLAF()->getHorizontalElementSpacing(getGUIType());
00807 }
00808
00809 void CSGrafikElement::setHorizontalElementSpacing(int horizontalElementSpacing)
00810 {
00811 mHorizontalElementSpacingSet = true;
00812 mHorizontalElementSpacing = horizontalElementSpacing;
00813 layoutChanged();
00814 }
00815
00816
00817 CSGrafikElement *CSGrafikElement::removeElement(CSGrafikElement *element)
00818 {
00819 static char *functionName="removeElement";
00820 if (mMainElement == this)
00821 {
00822 return removeMainElement(element);
00823 }
00824 CSGrafikElement *returnee = mMainElement->removeElement(element);
00825 layoutChanged();
00826 return returnee;
00827 }
00828
00829
00830 CSGrafikElement *CSGrafikElement::removeMainElement(CSGrafikElement *element)
00831 {
00832 static char *functionName="removeMainElement";
00833 LOG_ENTER
00834 CSGrafikElement *removedElement = 0;
00835 CSGrafikElements::iterator iter = mElements.begin();
00836 while (iter != mElements.end())
00837 {
00838 CSGrafikElement *test = *iter;
00839 if (test == element)
00840 {
00841 removedElement = test;
00842 mElements.erase(iter);
00843 removeMessageListener(test, GUI_MESSAGE);
00844
00845 if (getDesktop())
00846 {
00847 getDesktop()->correctElementHandling(test);
00848 }
00849
00850 test->setParent(0);
00851 test->mFrontElement = false;
00852 break;
00853 }
00854 iter++;
00855 }
00856 layoutChanged();
00857 LOG_EXIT
00858 return removedElement;
00859 }
00860
00861
00862
00863 void CSGrafikElement::addElement(CSGrafikElement *element, int x, int y)
00864 {
00865 static char *functionName="addElement";
00866 LOG_ENTER
00867
00868
00869 if (mMainElement == this)
00870 {
00871 addMainElement(element, x, y);
00872 }
00873 else
00874 {
00875 mMainElement->addElement(element, x, y);
00876 }
00877 LOG_EXIT
00878 }
00879
00880
00881
00882 void CSGrafikElement::addElement(CSGrafikElement *element, int position)
00883 {
00884 static char *functionName="addElement";
00885 LOG_ENTER
00886
00887
00888 if (mMainElement == this)
00889 {
00890 addMainElement(element, position);
00891 }
00892 else
00893 {
00894 mMainElement->addElement(element, position);
00895 }
00896 LOG_EXIT
00897 }
00898
00899 void CSGrafikElement::addElement(CSGrafikElement *element)
00900 {
00901 static char *functionName="addElement";
00902 LOG_ENTER
00903
00904
00905 if (mMainElement == this)
00906 {
00907 addMainElement(element);
00908 }
00909 else
00910 {
00911 mMainElement->addElement(element);
00912 }
00913 LOG_EXIT
00914 }
00915
00916
00917
00918 void CSGrafikElement::addMainElement(CSGrafikElement *element)
00919 {
00920 static char *functionName="addElement";
00921 LOG_ENTER
00922
00923 if (element->getParent())
00924 {
00925 element->getParent()->removeMainElement(element);
00926 }
00927 element->setParent(this);
00928 mElements.push_back(element);
00929 CSLayoutData *layoutData = element->getLayoutDataInternal();
00930 if (!layoutData->getSpacingSet())
00931 {
00932 layoutData->setSpacing(getVerticalElementSpacing(), getHorizontalElementSpacing());
00933 }
00934 element->setLayoutData(*layoutData);
00935 element->layoutChanged();
00936 LOG_EXIT
00937 }
00938
00939
00940
00941 void CSGrafikElement::addMainElement(CSGrafikElement *element, int position)
00942 {
00943 static char *functionName="addElement";
00944 LOG_ENTER
00945
00946 if (element->getParent())
00947 {
00948 element->getParent()->removeMainElement(element);
00949 }
00950 element->setParent(this);
00951 mElements.push_back(element);
00952 CSLayoutData *layoutData = element->getLayoutDataInternal();
00953 if (!layoutData->getSpacingSet())
00954 {
00955 layoutData->setSpacing(getVerticalElementSpacing(), getHorizontalElementSpacing());
00956 }
00957 layoutData->setPosition(position);
00958 element->setLayoutData(*layoutData);
00959 element->layoutChanged();
00960 LOG_EXIT
00961 }
00962
00963
00964
00965 void CSGrafikElement::addMainElement(CSGrafikElement *element, int x, int y)
00966 {
00967 static char *functionName="addElement";
00968 LOG_ENTER
00969
00970 if (element->getParent())
00971 {
00972 element->getParent()->removeMainElement(element);
00973 }
00974 element->setParent(this);
00975 mElements.push_back(element);
00976 CSLayoutData *layoutData = element->getLayoutDataInternal();
00977 if (!layoutData->getSpacingSet())
00978 {
00979 layoutData->setSpacing(getVerticalElementSpacing(), getHorizontalElementSpacing());
00980 }
00981 layoutData->setX(x);
00982 layoutData->setY(y);
00983 element->setLayoutData(*layoutData);
00984 element->layoutChanged();
00985 LOG_EXIT
00986 }
00987
00988 CSGrafikElement *CSGrafikElement::getUppermostAncestor()
00989 {
00990 static char *functionName="getUppermostAncestor";
00991 CSGrafikElement *parent = this;
00992 CSGrafikElement *lastParent = this;
00993 while (parent != 0)
00994 {
00995 lastParent = parent;
00996 parent = parent->getParent();
00997 }
00998 return lastParent;
00999 }
01000
01001
01002
01003
01004 void CSGrafikElement::addFrontElement(CSGrafikElement *element, int x, int y)
01005 {
01006 CSDesktop *desktop = getDesktop();
01007 if (desktop == 0)
01008 {
01009 return;
01010 }
01011 element->mFrontElement = true;
01012 getLayoutDataInternal()->setX(x);
01013 getLayoutDataInternal()->setY(y);
01014 desktop->addMainElement(element, x, y);
01015 }
01016
01017 void CSGrafikElement::addFrontElementCenter(CSGrafikElement *element)
01018 {
01019 CSDesktop *desktop = getDesktop();
01020 if (desktop == 0)
01021 {
01022 return;
01023 }
01024 element->mFrontElement = true;
01025 getLayoutDataInternal()->setX(desktop->getWidth()/2 - element->getWidth()/2);
01026 getLayoutDataInternal()->setY(desktop->getHeight()/2 - element->getHeight()/2);
01027 desktop->addMainElement(element, desktop->getWidth()/2 - element->getWidth()/2, desktop->getHeight()/2 - element->getHeight()/2);
01028 }
01029
01030 void CSGrafikElement::removeFrontElement(CSGrafikElement *element)
01031 {
01032 CSDesktop *desktop = getDesktop();
01033 if (desktop == 0)
01034 {
01035 return;
01036 }
01037 element->mFrontElement = false;
01038 desktop->removeMainElement(element);
01039 }
01040
01041 void CSGrafikElement::layoutChanged(bool sizing)
01042 {
01043 if ((!getLayoutManager()->getPropagateSizeChangesOnly()) || (sizing))
01044 {
01045 mLayoutChanged = true;
01046 }
01047
01048
01049
01050 if (sizing)
01051 {
01052 if (mParent != 0)
01053 {
01054 if (mParent->getLayoutManager()->getType().compare(CSLayoutManagerXY.CLASS) == 0)
01055 {
01056 mParent->mLayoutChanged = true;
01057 }
01058 else
01059 {
01060 mParent->layoutChanged(true);
01061 }
01062 }
01063 }
01064 else
01065 {
01066 if (mParent != 0)
01067 {
01068 if (!mParent->getLayoutManager()->getPropagateSizeChangesOnly())
01069 {
01070 mParent->mLayoutChanged = true;
01071 }
01072 }
01073 }
01074 }
01075
01076 void CSGrafikElement::doLayout()
01077 {
01078 static int i = 0;
01079 do {
01080 CSGrafikElements::iterator iter = mElements.begin();
01081 while (iter != mElements.end())
01082 {
01083 CSGrafikElement *element = (*iter);
01084 if (element->getVisible())
01085 {
01086 element->doLayout();
01087 }
01088 iter++;
01089 }
01090
01091 if (mLayoutChanged)
01092 {
01093 mLayoutChanged = false;
01094 layoutSetup();
01095 mLayoutManager->layout();
01096 i++;
01097 }
01098
01099 } while (mLayoutChanged);
01100 }
01101
01102 void CSGrafikElement::setVisible(bool v)
01103 {
01104 if (v != mVisible)
01105 {
01106 mVisible = v;
01107 layoutChanged(true);
01108 if (mParent)
01109 {
01110 mParent->layoutChanged();
01111 }
01112 }
01113 }
01114
01115 void CSGrafikElement::deleteElements()
01116 {
01117 if (mMainElement != this)
01118 {
01119 CSGrafikElements::iterator iter = mElements.begin();
01120 while (iter != mElements.end())
01121 {
01122 CSGrafikElement *element = *iter;
01123 if (element == mMainElement)
01124 {
01125 mElements.erase(iter);
01126 delete (element);
01127 break;
01128 }
01129 iter++;
01130 }
01131 mMainElement = this;
01132 }
01133
01134 CSGrafikElements::iterator iter = mElements.begin();
01135 while (iter != mElements.end())
01136 {
01137 CSGrafikElement *element = *iter;
01138 mElements.erase(iter);
01139 delete (element);
01140 iter = mElements.begin();
01141 }
01142
01143 }