00001 #ifdef WIN32
00002 #pragma warning(disable : 4786 )
00003 #endif
00004
00005 #include "CSLayoutManager.h"
00006 #include "CSGrafikElement.h"
00007 #include "CSBorder.h"
00008
00009 const char *CSLayoutManager::CLASS = "CSLayoutManager";
00010 const char *CSLayoutManagerXY::CLASS = "CSLayoutManagerXY";
00011 const char *CSLayoutManagerStackHorizontal::CLASS = "CSLayoutManagerStackHorizontal";
00012 const char *CSLayoutManagerStackVertical::CLASS = "CSLayoutManagerStackVertical";
00013 const char *CSLayoutManagerBorder::CLASS = "CSLayoutManagerBorder";
00014
00015
00016
00017
00018
00019 void CSLayoutData::init()
00020 {
00021 mX = 0;
00022 mY = 0;
00023 mPosition = POSITION_NOT_SET;
00024 mPackedHorizontal = false;
00025 mPackedVertical = false;
00026 mCenteredHorizontal = false;
00027 mCenteredVertical = false;
00028 mStretchedVertical = false;
00029 mStretchedHorizontal = false;
00030 mVerticalSpacing = 0;
00031 mHorizontalSpacing = 0;
00032 mSpacingSet = false;
00033
00034 }
00035 CSGrafikElements *CSLayoutManager::getElements(CSGrafikElement *element)
00036 {
00037 if (element)
00038 {
00039 return element->getElements();
00040 }
00041 return 0;
00042 }
00043
00044 void CSLayoutManager::layout()
00045 {
00046 CSGrafikElement *host = getHostingElement();
00047 if (host == 0)
00048 {
00049 return;
00050 }
00051 buildArea(host);
00052 layoutElements();
00053 }
00054
00055 bool CSLayoutManager::setLayout(CSGrafikElement *visitor, int x, int y, int width ,int height)
00056 {
00057 bool pos = false;
00058 bool size = false;
00059 if ((x != -1) && (y != -1))
00060 {
00061 if ((visitor->mX != x) || (visitor->mY != y))
00062 {
00063 pos = true;
00064 }
00065 if (x != -1)
00066 {
00067 visitor->mX = x;
00068 }
00069 if (y != -1)
00070 {
00071 visitor->mY = y;
00072 }
00073 }
00074 if (width != -1)
00075 {
00076 if (width < visitor->mMinWidth)
00077 {
00078 width = visitor->mMinWidth;
00079 }
00080 if (visitor->mWidth != width)
00081 {
00082 size = true;
00083 visitor->mWidth = width;
00084 visitor->mWidthSet = true;
00085 }
00086 }
00087 else
00088 {
00089
00090
00091 }
00092 if (height != -1)
00093 {
00094 if (height < visitor->mMinHeight)
00095 {
00096 height = visitor->mMinHeight;
00097 }
00098 if (visitor->mHeight != height)
00099 {
00100 size = true;
00101 visitor->mHeight = height;
00102 visitor->mHeightSet = true;
00103 }
00104 }
00105 else
00106 {
00107
00108
00109 }
00110
00111 if (pos | size)
00112 {
00113 buildArea(visitor);
00114
00115 if (size)
00116 {
00117
00118 visitor->layoutChanged(true);
00119 }
00120
00121 if ((pos) && (!mPropagateSizeChangesOnly))
00122 {
00123 visitor->layoutChanged();
00124 }
00125 }
00126 return pos | size;
00127 }
00128
00129 CSLayoutData *CSLayoutManager::getLayoutData(CSGrafikElement *visitor)
00130 {
00131 return visitor->getLayoutDataInternal();
00132 }
00133
00134 CSGrafikElement *CSLayoutManager::getParent(CSGrafikElement *element)
00135 {
00136 element = element->getParent();
00137 return element;
00138 }
00139
00140 int CSLayoutManager::getParentWidth(CSGrafikElement *element)
00141 {
00142 element = element->getParent();
00143 if (element)
00144 {
00145 return element->getViewportWidth();
00146 }
00147 return 0;
00148 }
00149
00150 int CSLayoutManager::getParentHeight(CSGrafikElement *element)
00151 {
00152 element = element->getParent();
00153 if (element)
00154 {
00155 return element->getViewportHeight();
00156 }
00157 return 0;
00158 }
00159
00160 int CSLayoutManager::getViewportWidth(CSGrafikElement *element)
00161 {
00162 return element->getViewportWidth();
00163 }
00164
00165 int CSLayoutManager::getViewportHeight(CSGrafikElement *element)
00166 {
00167 return element->getViewportHeight();
00168 }
00169
00170 int CSLayoutManager::getWidth(CSGrafikElement *element)
00171 {
00172 return element->getWidth();
00173 }
00174
00175 int CSLayoutManager::getHeight(CSGrafikElement *element)
00176 {
00177 return element->getHeight();
00178 }
00179
00180 int CSLayoutManager::getMinWidth(CSGrafikElement *element)
00181 {
00182 return element->getMinWidth();
00183 }
00184
00185 int CSLayoutManager::getMinHeight(CSGrafikElement *element)
00186 {
00187 return element->getMinHeight();
00188 }
00189
00190 int CSLayoutManager::getBorderWidth(CSGrafikElement *element)
00191 {
00192 return element->getBorder()->getTotalWidth();
00193 }
00194
00195 int CSLayoutManager::getBorderHeight(CSGrafikElement *element)
00196 {
00197 return element->getBorder()->getTotalHeight();
00198 }
00199
00200 int CSLayoutManager::getInsetWidth(CSGrafikElement *element)
00201 {
00202 return element->getInsetInternal()->getTotalWidth();
00203 }
00204
00205 int CSLayoutManager::getInsetHeight(CSGrafikElement *element)
00206 {
00207 return element->getInsetInternal()->getTotalHeight();
00208 }
00209
00210 void CSLayoutManager::pack(CSGrafikElement *element)
00211 {
00212 static char *functionName="buildArea";
00213
00214 if (element->mHeight < element->getLayoutManager()->getMinimumHeight(element))
00215 {
00216 element->mHeight = element->getLayoutManager()->getMinimumHeight(element);
00217 }
00218 if (element->mWidth < element->getLayoutManager()->getMinimumWidth(element))
00219 {
00220 element->mWidth = element->getLayoutManager()->getMinimumWidth(element);
00221 }
00222 buildArea(element);
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 void CSLayoutManager::buildArea(CSGrafikElement *element)
00236 {
00237 static char *functionName="buildArea";
00238 if (element->mHeight < getBorderHeight(element) + getInsetHeight(element))
00239 {
00240 element->mHeight = getBorderHeight(element) + getInsetHeight(element);
00241 }
00242 if (element->mWidth < getBorderWidth(element) + getInsetWidth(element))
00243 {
00244 element->mWidth = getBorderWidth(element) + getInsetWidth(element);
00245 }
00246
00247 element->mElementArea.x = element->mX;
00248 element->mElementArea.y = element->mY;
00249 element->mElementArea.h = element->mHeight;
00250 element->mElementArea.w = element->mWidth;
00251
00252 element->mViewportX = element->getBorder()->getSizeWest() + element->getInsetInternal()->getSizeWest();
00253 element->mViewportY = element->getBorder()->getSizeNorth() + element->getInsetInternal()->getSizeNorth();
00254 element->mViewportHeight = element->getHeight() - getBorderHeight(element) - getInsetHeight(element);
00255 element->mViewportWidth = element->getWidth() - getBorderWidth(element) - getInsetWidth(element);
00256
00257 if (element->mViewportHeight < 0) element->mViewportHeight = 0;
00258 if (element->mViewportWidth < 0) element->mViewportWidth = 0;
00259
00260 element->mViewportArea.x = element->mViewportX;
00261 element->mViewportArea.y = element->mViewportY;
00262 element->mViewportArea.h = element->mViewportHeight;
00263 element->mViewportArea.w = element->mViewportWidth;
00264
00265 element->getLayoutDataInternal()->setX(element->mX);
00266 element->getLayoutDataInternal()->setY(element->mY);
00267 }
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 void CSLayoutManagerXY::layoutElements()
00279 {
00280 CSGrafikElement *host = getHostingElement();
00281 if (host == 0)
00282 {
00283 return;
00284 }
00285
00286 CSLayoutData *layoutData = getLayoutData(host);
00287
00288 CSGrafikElements *elements = getElements(host);
00289 if (elements != 0)
00290 {
00291 CSGrafikElements::iterator iter = elements->begin();
00292 while (iter != elements->end())
00293 {
00294 CSGrafikElement *visitor = *iter;
00295 if (!visitor->getVisible())
00296 {
00297 iter++;
00298 continue;
00299 }
00300 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
00301 int x = visitorLayoutData->getX();
00302 int y = visitorLayoutData->getY();
00303 int w = -1;
00304 int h = -1;
00305
00306 if (visitorLayoutData->getPackedVertical())
00307 {
00308 h = visitor->getLayoutManager()->getMinimumHeight(visitor);
00309 }
00310 if (visitorLayoutData->getPackedHorizontal())
00311 {
00312 w = visitor->getLayoutManager()->getMinimumWidth(visitor);
00313 }
00314 setLayout(visitor, x , y, w, h);
00315 iter++;
00316 }
00317 }
00318 }
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361 void CSLayoutManagerBorder::layoutElements()
00362 {
00363 CSGrafikElement *host = getHostingElement();
00364 if (host == 0)
00365 {
00366 return;
00367 }
00368
00369 CSLayoutData *hostLayoutData = getLayoutData(host);
00370
00371 CSGrafikElements *elements = getElements(host);
00372 CSGrafikElements::iterator iter = elements->begin();
00373 CSGrafikElement *north = 0;
00374 CSGrafikElement *south = 0;
00375 CSGrafikElement *east = 0;
00376 CSGrafikElement *west = 0;
00377 CSGrafikElement *center = 0;
00378
00379 while (iter != elements->end())
00380 {
00381 CSGrafikElement *visitor = *iter;
00382 if (!visitor->getVisible())
00383 {
00384 iter++;
00385 continue;
00386 }
00387 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
00388
00389 switch (visitorLayoutData->getPosition())
00390 {
00391 case POSITION_NORTH:
00392 {
00393 north = visitor;
00394 break;
00395 }
00396 case POSITION_SOUTH:
00397 {
00398 south = visitor;
00399 break;
00400 }
00401 case POSITION_EAST:
00402 {
00403 east = visitor;
00404 break;
00405 }
00406 case POSITION_WEST:
00407 {
00408 west = visitor;
00409 break;
00410 }
00411 case POSITION_CENTER:
00412 {
00413 center = visitor;
00414 break;
00415 }
00416 default:
00417 {
00418 break;
00419 }
00420 }
00421 iter++;
00422 }
00423 int sizeNorthW = 10;
00424 int sizeSouthW = 10;
00425 int sizeEastW = 2;
00426 int sizeWestW = 2;
00427 int sizeCenterW = 6;
00428
00429 int sizeNorthH = 2;
00430 int sizeSouthH = 2;
00431 int sizeEastH = 6;
00432 int sizeWestH = 6;
00433 int sizeCenterH = 6;
00434
00435 if ((center == 0) && (east == 0) && (west == 0))
00436 {
00437 if (north)
00438 {
00439 sizeNorthH += sizeCenterH/2;
00440 }
00441 else
00442 {
00443 if (south)
00444 {
00445 sizeSouthH += sizeCenterH/2;
00446 }
00447 }
00448 if (south)
00449 {
00450 sizeSouthH += sizeCenterH/2;
00451 }
00452 else
00453 {
00454 if (north)
00455 {
00456 sizeNorthH += sizeCenterH/2;
00457 }
00458 }
00459 sizeCenterH = 0;
00460 }
00461 if (north == 0)
00462 {
00463 if (center)
00464 {
00465 sizeCenterH += sizeNorthH;
00466 }
00467 else
00468 {
00469 if (south)
00470 {
00471 sizeSouthH += sizeNorthH;
00472 }
00473 }
00474 sizeEastH += sizeNorthH;
00475 sizeWestH += sizeNorthH;
00476 sizeNorthH = 0;
00477 }
00478 if (south == 0)
00479 {
00480 if (center)
00481 {
00482 sizeCenterH += sizeSouthH;
00483 }
00484 else
00485 {
00486 if (north)
00487 {
00488 sizeNorthH += sizeSouthH;
00489 }
00490 }
00491 sizeEastH += sizeSouthH;
00492 sizeWestH += sizeSouthH;
00493 sizeSouthH = 0;
00494 }
00495 if (center == 0)
00496 {
00497 sizeEastW += sizeCenterW/2;
00498 sizeWestW += sizeCenterW/2;
00499 sizeCenterW = 0;
00500 }
00501 if (east == 0)
00502 {
00503 if (center)
00504 {
00505 sizeCenterW += sizeEastW;
00506 }
00507 else
00508 {
00509 sizeWestW += sizeEastW;
00510 }
00511 sizeEastW = 0;
00512 }
00513 if (west == 0)
00514 {
00515 if (center)
00516 {
00517 sizeCenterW += sizeWestW;
00518 }
00519 else
00520 {
00521 if (east)
00522 {
00523 sizeEastW += sizeWestW;
00524 }
00525 }
00526 sizeWestW = 0;
00527 }
00528 int width = getViewportWidth(host);
00529 int height = getViewportHeight(host);
00530
00531 int centerStartY = 0;
00532 int centerEndY = height;
00533 int centerStartX = 0;
00534 int centerEndX = width;
00535
00536 if (north)
00537 {
00538 CSLayoutData *layoutData = getLayoutData(north);
00539 int x = 0;
00540 int y = 0;
00541 int w = north->getWidth();
00542 int h = north->getHeight();
00543
00544 if (layoutData->getStretchedHorizontal())
00545 {
00546 w = (width * sizeNorthW)/10;
00547 }
00548 else if (layoutData->getPackedHorizontal())
00549 {
00550 w = north->getLayoutManager()->getMinimumWidth(north);
00551 }
00552 else
00553 {
00554 if (layoutData->getCenteredHorizontal())
00555 {
00556 x = (((width * sizeNorthW)/10) / 2) - w/2;
00557 if (x < 0)
00558 {
00559 x = 0;
00560 }
00561 }
00562 }
00563 if (layoutData->getStretchedVertical())
00564 {
00565 h = (height * sizeNorthH)/10;
00566 }
00567 else if (layoutData->getPackedVertical())
00568 {
00569 h = north->getLayoutManager()->getMinimumHeight(north);
00570 }
00571 if (layoutData->getCenteredVertical())
00572 {
00573 y = (((height * sizeNorthH)/10)/2) - h/2;
00574 if (y < 0)
00575 {
00576 y = 0;
00577 }
00578 }
00579 setLayout(north, x, y, w, h);
00580 centerStartY = y + h;
00581 }
00582 if (south)
00583 {
00584 CSLayoutData *layoutData = getLayoutData(south);
00585 int x = 0;
00586 int y = height - south->getHeight();
00587 if (y < 0)
00588 {
00589 y = 0;
00590 }
00591 int w = south->getWidth();
00592 int h = south->getHeight();
00593
00594 if (layoutData->getStretchedHorizontal())
00595 {
00596 w = (width * sizeSouthW)/10;
00597 }
00598 else
00599 {
00600 if (layoutData->getCenteredHorizontal())
00601 {
00602 x = (((width * sizeSouthW)/10) / 2) - w/2;
00603 if (x < 0)
00604 {
00605 x = 0;
00606 }
00607 }
00608 }
00609 if (layoutData->getStretchedVertical())
00610 {
00611 h = (height * sizeSouthH)/10;
00612 y = height - h;
00613 if (y < 0)
00614 {
00615 y = 0;
00616 }
00617 }
00618 else
00619 {
00620 if (layoutData->getPackedVertical())
00621 {
00622 h = south->getLayoutManager()->getMinimumHeight(south);
00623 }
00624 if (layoutData->getCenteredVertical())
00625 {
00626 y = 0;
00627 y += (height * sizeNorthH)/10;
00628 y += (height * sizeCenterH)/10;
00629 y += (((height * sizeSouthH)/10)/2);
00630 y -= h/2;
00631 if (y + h > height)
00632 {
00633 y = height - h;
00634 }
00635 if (y < 0)
00636 {
00637 y = 0;
00638 }
00639 }
00640 }
00641 setLayout(south, x, y, w , h);
00642 centerEndY = y;
00643 }
00644
00645 int westEndHorizontal = 0;
00646 if (west)
00647 {
00648 CSLayoutData *layoutData = getLayoutData(west);
00649 int x = 0;
00650 int y = centerStartY;
00651 int w = west->getWidth();
00652 int h = west->getHeight();
00653
00654 if (layoutData->getStretchedHorizontal())
00655 {
00656 w = (width * sizeWestW)/10;
00657 }
00658 else
00659 {
00660 if (layoutData->getPackedHorizontal())
00661 {
00662 w = west->getLayoutManager()->getMinimumWidth(west);
00663 }
00664 if (layoutData->getCenteredHorizontal())
00665 {
00666 x = (((width * sizeWestW)/10) / 2) - w/2;
00667 if (x <0)
00668 {
00669 x = 0;
00670 }
00671 }
00672 }
00673 if (layoutData->getStretchedVertical())
00674 {
00675 h = centerEndY - centerStartY;
00676 }
00677 else
00678 {
00679 if (layoutData->getCenteredVertical())
00680 {
00681 y = (((height * sizeWestH)/10)/2) - h/2 + ((height * sizeNorthH)/10);
00682 if (y < 0)
00683 {
00684 x = 0;
00685 }
00686 }
00687 }
00688
00689 setLayout(west, x, y, w , h);
00690 centerStartX = x + w;
00691 }
00692
00693 if (east)
00694 {
00695 CSLayoutData *layoutData = getLayoutData(east);
00696 int x = width - east->getWidth();
00697 if (x < 0)
00698 {
00699 x = 0;
00700 }
00701 int y = centerStartY;
00702 int w = east->getWidth();
00703 int h = east->getHeight();
00704 if (layoutData->getStretchedHorizontal())
00705 {
00706 w = (width * sizeEastW)/10;
00707 }
00708 else
00709 {
00710 if (layoutData->getPackedHorizontal())
00711 {
00712 w = east->getLayoutManager()->getMinimumWidth(east);
00713 }
00714 if (layoutData->getCenteredHorizontal())
00715 {
00716 x = (((width * sizeEastW)/10) / 2) - w/2 + ((width * sizeWestW)/10) + ((width * sizeCenterW)/10);
00717 if (x > width - w)
00718 {
00719 x = width - w;
00720 }
00721 if (x < 0)
00722 {
00723 x = 0;
00724 }
00725 }
00726 }
00727 if (layoutData->getStretchedVertical())
00728 {
00729 h = centerEndY - centerStartY;
00730 }
00731 else
00732 {
00733 if (layoutData->getCenteredVertical())
00734 {
00735 y = (((height * sizeEastH)/10)/2) - h/2 + ((height * sizeNorthH)/10);
00736 if (y < 0)
00737 {
00738 y = 0;
00739 }
00740 }
00741 }
00742 setLayout(east, x, y, w , h);
00743 centerEndX = x;
00744 }
00745
00746 if (center)
00747 {
00748 CSLayoutData *layoutData = getLayoutData(center);
00749 int x = centerStartX;
00750 int y = centerStartY;
00751 int w = center->getWidth();
00752 int h = center->getHeight();
00753 if (layoutData->getStretchedHorizontal())
00754 {
00755 w = centerEndX - centerStartX;
00756 }
00757 else
00758 {
00759 if (layoutData->getPackedHorizontal())
00760 {
00761 w = center->getLayoutManager()->getMinimumWidth(center);
00762 }
00763 if (layoutData->getCenteredHorizontal())
00764 {
00765 x += ((centerEndX - centerStartX) / 2) - w/2;
00766 }
00767 }
00768 if (layoutData->getStretchedVertical())
00769 {
00770 h = centerEndY - centerStartY;
00771 }
00772 else
00773 {
00774 if (layoutData->getPackedVertical())
00775 {
00776 h = center->getLayoutManager()->getMinimumHeight(center);
00777 }
00778 if (layoutData->getCenteredVertical())
00779 {
00780 y += ((centerEndY - centerStartY) / 2) - h/2;
00781 }
00782 }
00783 setLayout(center, x, y, w , h);
00784 }
00785 }
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795 void CSLayoutManagerStackHorizontal::layoutElements()
00796 {
00797 CSGrafikElement *host = getHostingElement();
00798 if (host == 0)
00799 {
00800 return;
00801 }
00802 CSGrafikElements *elements = getElements(host);
00803
00804 int verticalSpacing;
00805 int horizontalSpacing;
00806 CSLayoutData *layoutData = getLayoutData(host);
00807 layoutData->getSpacing(verticalSpacing, horizontalSpacing);
00808 int width;
00809 int height;
00810 width = getViewportWidth(host);
00811 height = getViewportHeight(host);
00812
00813 int x;
00814 int y = 0;
00815 int w, h;
00816 int stretchCounter = 0;
00817 int nonStretchSize = 0;
00818
00819 int packCounter = 0;
00820 int packSize = 0;
00821
00822 int verticalMinimum = 0;
00823 int horizontalMinimum = 0;
00824 int horizontalSpacingCollect = 0;
00825 int count = 0;
00826 CSGrafikElements::iterator iter = elements->begin();
00827 while (iter != elements->end())
00828 {
00829 CSGrafikElement *visitor = *iter;
00830 if (!visitor->getVisible())
00831 {
00832 iter++;
00833 continue;
00834 }
00835 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
00836 w = visitor->getWidth();
00837 if (visitorLayoutData->getStretchedHorizontal())
00838 {
00839 stretchCounter++;
00840 }
00841 else if (visitorLayoutData->getPackedHorizontal())
00842 {
00843 packSize += visitor->getLayoutManager()->getMinimumWidth(visitor);
00844 }
00845 else
00846 {
00847 nonStretchSize += w;
00848 }
00849
00850 horizontalMinimum += visitor->getLayoutManager()->getMinimumWidth(visitor);
00851
00852 if (verticalMinimum < visitor->getLayoutManager()->getMinimumHeight(visitor))
00853 {
00854 verticalMinimum = visitor->getLayoutManager()->getMinimumHeight(visitor);
00855 }
00856
00857 if (count != 0)
00858 {
00859 horizontalMinimum += horizontalSpacing;
00860 horizontalSpacingCollect += horizontalSpacing;
00861 if (visitorLayoutData->getPackedHorizontal())
00862 {
00863 packSize += horizontalSpacing;
00864 }
00865 }
00866 count++;
00867 iter++;
00868 }
00869
00870 if (height < verticalMinimum)
00871 {
00872 height = verticalMinimum;
00873 }
00874 if (width < horizontalMinimum)
00875 {
00876 width = horizontalMinimum;
00877 }
00878 int oneStretchedSize = 0;
00879 int xMax;
00880 int xMin;
00881 xMin = getViewportWidth(host);
00882 xMax = 0;
00883 if (stretchCounter)
00884 {
00885 oneStretchedSize = (width-horizontalSpacingCollect-nonStretchSize-packSize) / stretchCounter;
00886 }
00887 int stretchCounterNew = 0;
00888 count = 0;
00889 int leftCount = 0;
00890 int rightCount = 0;
00891 iter = elements->begin();
00892 while (iter != elements->end())
00893 {
00894 CSGrafikElement *visitor = *iter;
00895 if (!visitor->getVisible())
00896 {
00897 iter++;
00898 continue;
00899 }
00900 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
00901 y = 0;
00902 w = visitor->getWidth();
00903 h = visitor->getHeight();
00904 if (visitorLayoutData->getStretchedHorizontal())
00905 {
00906 w = oneStretchedSize;
00907 stretchCounterNew++;
00908 if (stretchCounterNew < (width-horizontalSpacingCollect-nonStretchSize-packSize) - oneStretchedSize * stretchCounter)
00909 {
00910 w++;
00911 }
00912 }
00913 else if (visitorLayoutData->getPackedHorizontal())
00914 {
00915 if (visitorLayoutData->getPosition() == POSITION_ORDER_LEFT)
00916 {
00917 w = visitor->getLayoutManager()->getMinimumWidth(visitor);
00918 }
00919 if (visitorLayoutData->getPosition() == POSITION_ORDER_RIGHT)
00920 {
00921 w = visitor->getLayoutManager()->getMinimumWidth(visitor);
00922 }
00923 }
00924 else
00925 {
00926
00927 int w2 = visitor->getLayoutManager()->getMinimumWidth(visitor);
00928 if (w2 > w)
00929 {
00930 w = w2;
00931 }
00932
00933 }
00934
00935 if (visitorLayoutData->getStretchedVertical())
00936 {
00937 h = height;
00938 }
00939 else if (visitorLayoutData->getPackedVertical())
00940 {
00941 h = visitor->getLayoutManager()->getMinimumHeight(visitor);
00942 }
00943 else
00944 {
00945
00946 int h2 = visitor->getLayoutManager()->getMinimumHeight(visitor);
00947 if (h2 > h)
00948 {
00949 h = h2;
00950 }
00951 }
00952 if (visitorLayoutData->getCenteredVertical())
00953 {
00954 y = height/2 - h/2;
00955 }
00956 if (visitorLayoutData->getPosition() == POSITION_ORDER_LEFT)
00957 {
00958 if (leftCount != 0)
00959 {
00960 xMax += horizontalSpacing;
00961 }
00962 leftCount++;
00963 x = xMax;
00964 xMax += w;
00965 }
00966 else if (visitorLayoutData->getPosition() == POSITION_ORDER_RIGHT)
00967 {
00968 if (rightCount != 0)
00969 {
00970 xMin -= horizontalSpacing;
00971 }
00972 rightCount++;
00973 xMin -= w;
00974 x = xMin;
00975 }
00976 else
00977 {
00978 x = width/2 - w/2;
00979 }
00980 setLayout(visitor, x, y, w, h);
00981 count++;
00982 iter++;
00983 }
00984 }
00985
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995 void CSLayoutManagerStackVertical::layoutElements()
00996 {
00997 CSGrafikElement *host = getHostingElement();
00998 if (host == 0)
00999 {
01000 return;
01001 }
01002 CSGrafikElements *elements = getElements(host);
01003
01004 int verticalSpacing;
01005 int horizontalSpacing;
01006
01007 CSLayoutData *layoutData = getLayoutData(host);
01008 layoutData->getSpacing(verticalSpacing, horizontalSpacing);
01009 int width;
01010 int height;
01011 width = getViewportWidth(host);
01012 height = getViewportHeight(host);
01013
01014 int x = 0;
01015 int y;
01016 int w, h;
01017 int stretchCounter = 0;
01018 int nonStretchSize = 0;
01019
01020 int packCounter = 0;
01021 int packSize = 0;
01022
01023 int verticalMinimum = 0;
01024 int horizontalMinimum = 0;
01025 int verticalSpacingCollect = 0;
01026 int count = 0;
01027 CSGrafikElements::iterator iter = elements->begin();
01028 while (iter != elements->end())
01029 {
01030 CSGrafikElement *visitor = *iter;
01031 if (!visitor->getVisible())
01032 {
01033 iter++;
01034 continue;
01035 }
01036 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
01037 h = visitor->getHeight();
01038 if (visitorLayoutData->getStretchedVertical())
01039 {
01040 stretchCounter++;
01041 }
01042 else if (visitorLayoutData->getPackedVertical())
01043 {
01044 packSize += visitor->getLayoutManager()->getMinimumHeight(visitor);
01045 }
01046 else
01047 {
01048 nonStretchSize += h;
01049 }
01050
01051 verticalMinimum += visitor->getLayoutManager()->getMinimumHeight(visitor);
01052 if (horizontalMinimum < visitor->getLayoutManager()->getMinimumWidth(visitor))
01053 {
01054 horizontalMinimum = visitor->getLayoutManager()->getMinimumWidth(visitor);
01055 }
01056 if (count != 0)
01057 {
01058 verticalMinimum += verticalSpacing;
01059 verticalSpacingCollect += verticalSpacing;
01060 if (visitorLayoutData->getPackedVertical())
01061 {
01062 packSize += verticalSpacing;
01063 }
01064 }
01065 count++;
01066 iter++;
01067 }
01068
01069 if (height < verticalMinimum)
01070 {
01071 height = verticalMinimum;
01072 }
01073 if (width < horizontalMinimum)
01074 {
01075 width = horizontalMinimum;
01076 }
01077 int oneStretchedSize = 0;
01078 int yMax;
01079 int yMin;
01080 yMin = getViewportHeight(host);
01081 yMax = 0;
01082 if (stretchCounter)
01083 {
01084 oneStretchedSize = ((height-verticalSpacingCollect)-nonStretchSize-packSize) / stretchCounter;
01085 }
01086 int stretchCounterNew = 0;
01087 count = 0;
01088 int topCount = 0;
01089 int bottomCount = 0;
01090 iter = elements->begin();
01091 while (iter != elements->end())
01092 {
01093 CSGrafikElement *visitor = *iter;
01094 if (!visitor->getVisible())
01095 {
01096 iter++;
01097 continue;
01098 }
01099 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
01100 x = 0;
01101 w = visitor->getWidth();
01102 h = visitor->getHeight();
01103 if (visitorLayoutData->getStretchedVertical())
01104 {
01105 h = oneStretchedSize;
01106 stretchCounterNew++;
01107 if (stretchCounterNew < (height- verticalSpacingCollect-nonStretchSize-packSize) - oneStretchedSize * stretchCounter)
01108 {
01109 h++;
01110 }
01111 }
01112 else if (visitorLayoutData->getPackedVertical())
01113 {
01114 if (visitorLayoutData->getPosition() == POSITION_ORDER_TOP)
01115 {
01116 h = visitor->getLayoutManager()->getMinimumHeight(visitor);
01117 }
01118 if (visitorLayoutData->getPosition() == POSITION_ORDER_BOTTOM)
01119 {
01120 h = visitor->getLayoutManager()->getMinimumHeight(visitor);
01121 }
01122 }
01123 else
01124 {
01125 int h2 = visitor->getLayoutManager()->getMinimumHeight(visitor);
01126 if (h < h2)
01127 {
01128 h = h2;
01129 }
01130 }
01131
01132 if (visitorLayoutData->getStretchedHorizontal())
01133 {
01134 w = width;
01135 }
01136 else if (visitorLayoutData->getPackedHorizontal())
01137 {
01138 w = visitor->getLayoutManager()->getMinimumWidth(visitor);
01139 }
01140 else
01141 {
01142 int w2 = visitor->getLayoutManager()->getMinimumWidth(visitor);
01143 if (w < w2)
01144 {
01145 w = w2;
01146 }
01147 }
01148 if (visitorLayoutData->getCenteredHorizontal())
01149 {
01150 x = width/2 - w/2;
01151 }
01152 if (visitorLayoutData->getPosition() == POSITION_ORDER_TOP)
01153 {
01154 if (topCount)
01155 {
01156 yMax += verticalSpacing;
01157 }
01158 topCount++;
01159 y = yMax;
01160 yMax += h;
01161 }
01162 else if (visitorLayoutData->getPosition() == POSITION_ORDER_BOTTOM)
01163 {
01164 if (bottomCount)
01165 {
01166 yMin -= verticalSpacing;
01167 }
01168 bottomCount++;
01169 yMin -= h;
01170 y = yMin;
01171 }
01172 else
01173 {
01174 y = height/2 - h/2;
01175 }
01176 setLayout(visitor, x, y, w, h);
01177 count++;
01178 iter++;
01179 }
01180 }
01181
01182
01183
01184
01185
01186 int CSLayoutManagerStackHorizontal::getMinimumHeight(CSGrafikElement *element)
01187 {
01188 if (element == 0)
01189 {
01190 return 0;
01191 }
01192 if (!element->getVisible())
01193 {
01194 return 0;
01195 }
01196 int height = getMinHeight(element);
01197 CSGrafikElements *elements = getElements(element);
01198
01199 if (!elements == 0)
01200 {
01201 CSGrafikElements::iterator iter = elements->begin();
01202 while (iter != elements->end())
01203 {
01204 int neededHeight;
01205 CSGrafikElement *visitor = *iter;
01206 neededHeight = visitor->getLayoutManager()->getMinimumHeight(visitor);
01207
01208 if (height < neededHeight)
01209 {
01210 height = neededHeight;
01211 }
01212 iter++;
01213 }
01214 }
01215 height += getInsetHeight(element) + getBorderHeight(element);
01216 return height;
01217 }
01218
01219 int CSLayoutManagerXY::getMinimumHeight(CSGrafikElement *element)
01220 {
01221 if (element == 0)
01222 {
01223 return 0;
01224 }
01225 if (!element->getVisible())
01226 {
01227 return 0;
01228 }
01229 int height = getMinHeight(element);
01230 CSGrafikElements *elements = getElements(element);
01231
01232 CSLayoutData *layoutData = getLayoutData(element);
01233
01234 if (elements != 0)
01235 {
01236 CSGrafikElements::iterator iter = elements->begin();
01237 while (iter != elements->end())
01238 {
01239 CSGrafikElement *visitor = *iter;
01240 if (!visitor->getVisible())
01241 {
01242 iter++;
01243 continue;
01244 }
01245 CSLayoutData visitorLayoutData = visitor->getLayoutData();
01246 int h = visitor->getLayoutManager()->getMinimumHeight(visitor);
01247 if (!mComponentSizeOnly)
01248 {
01249 h += visitorLayoutData.getY();
01250 }
01251
01252
01253 if ( h > height)
01254 {
01255 height = h;
01256 }
01257 iter++;
01258 }
01259 }
01260 height += getInsetHeight(element) + getBorderHeight(element);
01261 return height;
01262 }
01263
01264 int CSLayoutManagerStackVertical::getMinimumHeight(CSGrafikElement *element)
01265 {
01266 if (element == 0)
01267 {
01268 return 0;
01269 }
01270 if (!element->getVisible())
01271 {
01272 return 0;
01273 }
01274 int height = getMinHeight(element);
01275 CSGrafikElements *elements = getElements(element);
01276
01277 int verticalSpacing;
01278 int horizontalSpacing;
01279
01280 CSLayoutData *layoutData = getLayoutData(element);
01281 layoutData->getSpacing(verticalSpacing, horizontalSpacing);
01282
01283 if (!elements == 0)
01284 {
01285 int neededHeight = 0;
01286 int count = 0;
01287 CSGrafikElements::iterator iter = elements->begin();
01288 while (iter != elements->end())
01289 {
01290 CSGrafikElement *visitor = *iter;
01291 if (!visitor->getVisible())
01292 {
01293 iter++;
01294 continue;
01295 }
01296 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
01297
01298 int visitorHeight = visitor->getLayoutManager()->getMinimumHeight(visitor);
01299 if (count != 0)
01300 {
01301 visitorHeight += verticalSpacing;
01302 }
01303
01304 neededHeight += visitorHeight;
01305 iter++;
01306 count++;
01307 }
01308 if (neededHeight > height)
01309 {
01310 height = neededHeight;
01311 }
01312 }
01313
01314 height += getInsetHeight(element) + getBorderHeight(element);
01315 return height;
01316 }
01317
01318 int CSLayoutManagerBorder::getMinimumHeight(CSGrafikElement *element)
01319 {
01320 if (element == 0)
01321 {
01322 return 0;
01323 }
01324 if (!element->getVisible())
01325 {
01326 return 0;
01327 }
01328 int height = getMinHeight(element);
01329 CSGrafikElements *elements = getElements(element);
01330 CSGrafikElements::iterator iter = elements->begin();
01331
01332 CSGrafikElement *north = 0;
01333 CSGrafikElement *south = 0;
01334 CSGrafikElement *east = 0;
01335 CSGrafikElement *west = 0;
01336 CSGrafikElement *center = 0;
01337
01338 while (iter != elements->end())
01339 {
01340 CSGrafikElement *visitor = *iter;
01341 if (!visitor->getVisible())
01342 {
01343 iter++;
01344 continue;
01345 }
01346 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
01347 switch (visitorLayoutData->getPosition())
01348 {
01349 case POSITION_NORTH:
01350 {
01351 north = visitor;
01352 break;
01353 }
01354 case POSITION_SOUTH:
01355 {
01356 south = visitor;
01357 break;
01358 }
01359 case POSITION_EAST:
01360 {
01361 east = visitor;
01362 break;
01363 }
01364 case POSITION_WEST:
01365 {
01366 west = visitor;
01367 break;
01368 }
01369 case POSITION_CENTER:
01370 {
01371 center = visitor;
01372 break;
01373 }
01374 default:
01375 {
01376 break;
01377 }
01378 }
01379 iter++;
01380 }
01381
01382 int verticalSpacing;
01383 int horizontalSpacing;
01384 CSLayoutData *layoutData = getLayoutData(element);
01385 layoutData->getSpacing(verticalSpacing, horizontalSpacing);
01386
01387 int neededHeight = 0;
01388 if ((north) && ((center) || (east) || (west)) && (south))
01389 {
01390 neededHeight += verticalSpacing;
01391 neededHeight += verticalSpacing;
01392 }
01393 else if ((north) && ((center) || (east) || (west)))
01394 {
01395 neededHeight += verticalSpacing;
01396 }
01397 else if (((center) || (east) || (west)) && (south))
01398 {
01399 neededHeight += verticalSpacing;
01400 }
01401 else if ((north) && (south))
01402 {
01403 neededHeight += verticalSpacing;
01404 }
01405
01406 if (north)
01407 {
01408 neededHeight += north->getLayoutManager()->getMinimumHeight(north);
01409 }
01410 if ((center) || (east) || (west))
01411 {
01412 int maxHeight = 0;
01413 int centerHeight = 0;
01414 int eastHeight = 0;
01415 int westHeight = 0;
01416
01417 if (center)
01418 {
01419 centerHeight = center->getLayoutManager()->getMinimumHeight(center);
01420 }
01421 if (east)
01422 {
01423 eastHeight = east->getLayoutManager()->getMinimumHeight(east);
01424 }
01425 if (west)
01426 {
01427 westHeight = west->getLayoutManager()->getMinimumHeight(west);
01428 }
01429
01430 maxHeight = centerHeight;
01431 if (eastHeight>maxHeight)
01432 {
01433 maxHeight = eastHeight;
01434 }
01435 if (westHeight>maxHeight)
01436 {
01437 maxHeight = westHeight;
01438 }
01439
01440 neededHeight += maxHeight;
01441 }
01442 if (south)
01443 {
01444 neededHeight += south->getLayoutManager()->getMinimumHeight(south);
01445 }
01446
01447 if (neededHeight > height)
01448 {
01449 height = neededHeight;
01450 }
01451
01452 height += getInsetHeight(element) + getBorderHeight(element);
01453 return height;
01454 }
01455
01456 int CSLayoutManagerStackHorizontal::getMinimumWidth(CSGrafikElement *element)
01457 {
01458 if (element == 0)
01459 {
01460 return 0;
01461 }
01462 if (!element->getVisible())
01463 {
01464 return 0;
01465 }
01466 int width = getMinWidth(element);
01467 CSGrafikElements *elements = getElements(element);
01468
01469 int verticalSpacing;
01470 int horizontalSpacing;
01471
01472 CSLayoutData *layoutData = getLayoutData(element);
01473 layoutData->getSpacing(verticalSpacing, horizontalSpacing);
01474
01475 if (!elements == 0)
01476 {
01477 int neededWidth = 0;
01478 int count = 0;
01479 CSGrafikElements::iterator iter = elements->begin();
01480 while (iter != elements->end())
01481 {
01482 CSGrafikElement *visitor = *iter;
01483 if (!visitor->getVisible())
01484 {
01485 iter++;
01486 continue;
01487 }
01488 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
01489
01490 int visitorWidth = visitor->getLayoutManager()->getMinimumWidth(visitor);
01491 if (count != 0)
01492 {
01493 visitorWidth += horizontalSpacing;
01494 }
01495
01496 neededWidth += visitorWidth;
01497 iter++;
01498 count++;
01499 }
01500 if (neededWidth > width)
01501 {
01502 width = neededWidth;
01503 }
01504 }
01505 width += getInsetWidth(element) + getBorderWidth(element);
01506 return width;
01507 }
01508
01509 int CSLayoutManagerXY::getMinimumWidth(CSGrafikElement *element)
01510 {
01511 if (element == 0)
01512 {
01513 return 0;
01514 }
01515 if (!element->getVisible())
01516 {
01517 return 0;
01518 }
01519 int width = getMinWidth(element);
01520 CSGrafikElements *elements = getElements(element);
01521
01522 CSLayoutData *layoutData = getLayoutData(element);
01523
01524 if (elements != 0)
01525 {
01526 CSGrafikElements::iterator iter = elements->begin();
01527 while (iter != elements->end())
01528 {
01529 CSGrafikElement *visitor = *iter;
01530 if (!visitor->getVisible())
01531 {
01532 iter++;
01533 continue;
01534 }
01535 CSLayoutData visitorLayoutData = visitor->getLayoutData();
01536 int w = visitor->getLayoutManager()->getMinimumWidth(visitor);
01537 if (!mComponentSizeOnly)
01538 {
01539 w += visitorLayoutData.getX();
01540 }
01541 if ( w > width)
01542 {
01543 width = w;
01544 }
01545 iter++;
01546 }
01547 }
01548 width += getInsetWidth(element) + getBorderWidth(element);
01549 return width;
01550 }
01551
01552 int CSLayoutManagerStackVertical::getMinimumWidth(CSGrafikElement *element)
01553 {
01554 if (element == 0)
01555 {
01556 return 0;
01557 }
01558 if (!element->getVisible())
01559 {
01560 return 0;
01561 }
01562 int width = getMinWidth(element);
01563 CSGrafikElements *elements = getElements(element);
01564
01565 int verticalSpacing;
01566 int horizontalSpacing;
01567
01568
01569 CSLayoutData *layoutData = getLayoutData(element);
01570 layoutData->getSpacing(verticalSpacing, horizontalSpacing);
01571
01572 if (!elements == 0)
01573 {
01574 int neededWidth = 0;
01575 CSGrafikElements::iterator iter = elements->begin();
01576 while (iter != elements->end())
01577 {
01578 CSGrafikElement *visitor = *iter;
01579 if (!visitor->getVisible())
01580 {
01581 iter++;
01582 continue;
01583 }
01584
01585 int visitorWidth = visitor->getLayoutManager()->getMinimumWidth(visitor);
01586
01587 if (visitorWidth > neededWidth)
01588 {
01589 neededWidth = visitorWidth;
01590 }
01591 iter++;
01592 }
01593 if (neededWidth > width)
01594 {
01595 width = neededWidth;
01596 }
01597 }
01598
01599 width += getInsetWidth(element) + getBorderWidth(element);
01600 return width;
01601 }
01602
01603 int CSLayoutManagerBorder::getMinimumWidth(CSGrafikElement *element)
01604 {
01605 if (element == 0)
01606 {
01607 return 0;
01608 }
01609 if (!element->getVisible())
01610 {
01611 return 0;
01612 }
01613 int width = getMinWidth(element);
01614 CSGrafikElements *elements = getElements(element);
01615 CSGrafikElements::iterator iter = elements->begin();
01616
01617 CSGrafikElement *north = 0;
01618 CSGrafikElement *south = 0;
01619 CSGrafikElement *east = 0;
01620 CSGrafikElement *west = 0;
01621 CSGrafikElement *center = 0;
01622
01623 while (iter != elements->end())
01624 {
01625 CSGrafikElement *visitor = *iter;
01626 if (!visitor->getVisible())
01627 {
01628 iter++;
01629 continue;
01630 }
01631 CSLayoutData *visitorLayoutData = getLayoutData(visitor);
01632 switch (visitorLayoutData->getPosition())
01633 {
01634 case POSITION_NORTH:
01635 {
01636 north = visitor;
01637 break;
01638 }
01639 case POSITION_SOUTH:
01640 {
01641 south = visitor;
01642 break;
01643 }
01644 case POSITION_EAST:
01645 {
01646 east = visitor;
01647 break;
01648 }
01649 case POSITION_WEST:
01650 {
01651 west = visitor;
01652 break;
01653 }
01654 case POSITION_CENTER:
01655 {
01656 center = visitor;
01657 break;
01658 }
01659 default:
01660 {
01661 break;
01662 }
01663 }
01664 iter++;
01665 }
01666
01667 int verticalSpacing;
01668 int horizontalSpacing;
01669
01670
01671 CSLayoutData *layoutData = getLayoutData(element);
01672 layoutData->getSpacing(verticalSpacing, horizontalSpacing);
01673
01674 int neededWidth = 0;
01675 int centralWidth = 0;
01676 int maxWidth = 0;
01677 int northWidth = 0;
01678 int southWidth = 0;
01679
01680 if ((west) && (center) && (east))
01681 {
01682 centralWidth += horizontalSpacing;
01683 centralWidth += horizontalSpacing;
01684 }
01685 else if ((west) && (center))
01686 {
01687 centralWidth += horizontalSpacing;
01688 }
01689 else if ((center) && (east))
01690 {
01691 centralWidth += horizontalSpacing;
01692 }
01693 else if ((west) && (east))
01694 {
01695 centralWidth += horizontalSpacing;
01696 }
01697 if (west)
01698 {
01699 centralWidth += west->getLayoutManager()->getMinimumWidth(west);
01700 }
01701 if (center)
01702 {
01703 centralWidth += center->getLayoutManager()->getMinimumWidth(center);
01704 }
01705 if (east)
01706 {
01707 centralWidth += east->getLayoutManager()->getMinimumWidth(east);
01708 }
01709
01710 if (north)
01711 {
01712 northWidth += north->getLayoutManager()->getMinimumWidth(north);
01713 }
01714 if (south)
01715 {
01716 southWidth += south->getLayoutManager()->getMinimumWidth(south);
01717 }
01718
01719 maxWidth = centralWidth;
01720 if (northWidth >maxWidth)
01721 {
01722 maxWidth = northWidth;
01723 }
01724 if (southWidth >maxWidth)
01725 {
01726 maxWidth = southWidth;
01727 }
01728
01729 if (maxWidth > width)
01730 {
01731 width = maxWidth;
01732 }
01733
01734 width += getInsetWidth(element) + getBorderWidth(element);
01735 return width;
01736 }
01737