Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSGrafikElement_old.cpp

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

Generated on Wed Jul 14 00:43:30 2004 for CSLib by doxygen 1.3.6