Mailinglist Archive: yast-commit (490 mails)
| < Previous | Next > |
[yast-commit] r39004 - in /branches/tmp/sh/mod-ui/core/libyui/src: YLayoutBox.cc YLayoutBox.h
- From: sh-sh-sh@xxxxxxxxxxxxxxxx
- Date: Mon, 25 Jun 2007 14:33:56 -0000
- Message-id: <20070625143356.353A1C544F@xxxxxxxxxxxxxxxx>
Author: sh-sh-sh
Date: Mon Jun 25 16:33:55 2007
New Revision: 39004
URL: http://svn.opensuse.org/viewcvs/yast?rev=39004&view=rev
Log:
ported to preferredWidth() / -Height()
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc
branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc?rev=39004&r1=39003&r2=39004&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc Mon Jun 25 16:33:55 2007
@@ -96,12 +96,12 @@
}
-long
-YLayoutBox::nicesize( YUIDimension dimension )
+void
+YLayoutBox::preferredSize( YUIDimension dimension )
{
if ( dimension == secondary() ) // the easy case first: secondary dimension
{
- return childrenMaxNiceSize( dimension );
+ return childrenMaxPreferredSize( dimension );
}
else
{
@@ -113,11 +113,11 @@
* know that, we need to stretch all other weighted children accordingly
* so the weight ratios are respected.
*
- * As a final step, the nice sizes of all children that don't have
+ * As a final step, the preferred sizes of all children that don't have
* a weight attached are summed up.
*/
- long size = 0L;
+ int size = 0L;
// Search for the dominating child
YWidget * dominatingChild = findDominatingChild();
@@ -126,7 +126,7 @@
{
// Calculate size of all weighted widgets.
- size = dominatingChild->nicesize( primary() )
+ size = dominatingChild->preferredSize( primary() )
* childrenTotalWeight( primary() )
/ dominatingChild->weight( primary() );
@@ -136,21 +136,33 @@
// Add up the size of all non-weighted children;
- // they will get their respective nice size.
+ // they will get their respective preferred size.
- size += totalNonWeightedChildrenNiceSize( primary() );
+ size += totalNonWeightedChildrenPreferredSize( primary() );
return size;
}
}
+int YLayoutBox::preferredWidth()
+{
+ return preferredSize( YD_HORIZ );
+}
+
+
+int YLayoutBox::preferredHeight()
+{
+ return preferredSize( YD_VERT );
+}
+
+
/*
* Search for the "dominating child" widget.
*
* This is the widget that determines the overall size of the
* container with respect to all children's weights: It is the child
- * with the maximum ratio of nice size and weight. All other
+ * with the maximum ratio of preferred size and weight. All other
* weighted children need to be stretched accordingly so the weight
* ratios can be maintained.
*
@@ -173,7 +185,7 @@
if ( child->weight( primary() ) != 0 ) // avoid division by zero
{
- ratio = ( ( double ) child->nicesize( primary() ) )
+ ratio = ( ( double ) child->preferredSize( primary() ) )
/ child->weight( primary() );
if ( ratio > dominatingRatio ) // we have a new dominating child
@@ -190,9 +202,9 @@
if ( dominatingChild >= 0 )
{
y2debug( "YLayoutBox::findDominatingChild(): "
- "Found dominating child: %s - nice size: %ld, weight: %ld",
+ "Found dominating child: %s - preferred size: %d, weight: %d",
dominatingChild->widgetClass(),
- dominatingChild->nicesize( primary() ),
+ dominatingChild->preferredSize( primary() ),
dominatingChild->weight( primary() ) );
}
else
@@ -206,26 +218,26 @@
}
-long
-YLayoutBox::childrenMaxNiceSize( YUIDimension dimension )
+int
+YLayoutBox::childrenMaxPreferredSize( YUIDimension dimension )
{
- long maxNiceSize = 0L;
+ int maxPreferredSize = 0L;
for ( YWidgetListConstIterator it = childrenBegin();
it != childrenEnd();
++it )
{
- maxNiceSize = std::max( (*it)->nicesize( dimension ), maxNiceSize );
+ maxPreferredSize = std::max( (*it)->preferredSize( dimension ), maxPreferredSize );
}
- return maxNiceSize;
+ return maxPreferredSize;
}
-long
+int
YLayoutBox::childrenTotalWeight( YUIDimension dimension )
{
- long totalWeight = 0L;
+ int totalWeight = 0L;
for ( YWidgetListConstIterator it = childrenBegin();
it != childrenEnd();
@@ -238,17 +250,17 @@
}
-long
-YLayoutBox::totalNonWeightedChildrenNiceSize( YUIDimension dimension )
+int
+YLayoutBox::totalNonWeightedChildrenPreferredSize( YUIDimension dimension )
{
- long size = 0L;
+ int size = 0L;
for ( YWidgetListConstIterator it = childrenBegin();
it != childrenEnd();
++it )
{
if ( ! (*it)->hasWeight( dimension ) ) // non-weighted children only
- size += (*it)->nicesize( dimension );
+ size += (*it)->preferredSize( dimension );
}
return size;
@@ -341,7 +353,7 @@
void
-YLayoutBox::setSize( long newWidth, long newHeight )
+YLayoutBox::setSize( int newWidth, int newHeight )
{
int count = childrenCount();
sizeVector widths ( count );
@@ -374,24 +386,24 @@
void
-YLayoutBox::calcPrimaryGeometry( long newSize,
+YLayoutBox::calcPrimaryGeometry( int newSize,
sizeVector & childSize,
posVector & childPos )
{
- long pos = 0L;
- long distributableSize = newSize - totalNonWeightedChildrenNiceSize( primary() );
+ int pos = 0L;
+ int distributableSize = newSize - totalNonWeightedChildrenPreferredSize( primary() );
if ( distributableSize >= 0L )
{
// The (hopefully) normal case: There is enough space.
- // The non-weighted children will get their nice sizes,
+ // The non-weighted children will get their preferred sizes,
// the rest will be distributed among the weighted children
// according to their respective weight ratios.
- long nonWeightedExtra = 0L;
- long totalWeight = childrenTotalWeight( primary() );
+ int nonWeightedExtra = 0L;
+ int totalWeight = childrenTotalWeight( primary() );
int rubberBands = 0;
- long rubberBandExtra = 0L;
+ int rubberBandExtra = 0L;
if ( totalWeight <= 0 )
{
@@ -408,14 +420,14 @@
{
// If there are weighted children and there are rubber band
// widgets, equally divide any surplus space (i.e. space that
- // exceeds the weighted children's nice sizes with respect to
+ // exceeds the weighted children's preferred sizes with respect to
// their weights) between the rubber bands.
//
- // This offers an easy way to make nice even spaced buttons
+ // This offers an easy way to make nicely even spaced buttons
// of equal size: Give all buttons a weight of 1 and insert a
// stretch (without weight!) between each.
- long surplusSize = newSize - nicesize( primary() );
+ int surplusSize = newSize - preferredSize( primary() );
if ( surplusSize > 0L )
{
@@ -432,12 +444,12 @@
if ( debugLayout() )
{
y2debug( "Distributing extra space" );
- y2debug( "new size: %ld", newSize );
- y2debug( "distributable size: %ld", distributableSize );
- y2debug( "rubber band extra: %ld", rubberBandExtra );
+ y2debug( "new size: %d", newSize );
+ y2debug( "distributable size: %d", distributableSize );
+ y2debug( "rubber band extra: %d", rubberBandExtra );
y2debug( "rubber bands: %d", rubberBands );
- y2debug( "total weight: %ld", totalWeight );
- y2debug( "non weighted extra: %ld", nonWeightedExtra );
+ y2debug( "total weight: %d", totalWeight );
+ y2debug( "non weighted extra: %d", nonWeightedExtra );
}
int i=0;
@@ -453,18 +465,18 @@
childSize[i] = distributableSize * child->weight( primary() ) / totalWeight;
- if ( childSize[i] < child->nicesize( primary() ) )
+ if ( childSize[i] < child->preferredSize( primary() ) )
{
- y2debug( "Resizing child widget #%d (%s) below its nice size of %ld to %ld "
+ y2debug( "Resizing child widget #%d (%s) below its preferred size of %d to %d "
"- check the layout!",
- i, child->widgetClass(), child->nicesize( primary() ), childSize[i] );
+ i, child->widgetClass(), child->preferredSize( primary() ), childSize[i] );
}
}
else
{
- // Non-weighted children will get their nice size.
+ // Non-weighted children will get their preferred size.
- childSize[i] = child->nicesize( primary() );
+ childSize[i] = child->preferredSize( primary() );
if ( child->stretchable( primary() ) )
@@ -478,7 +490,7 @@
if ( isLayoutStretch( child, primary() ) )
{
- // If there is more than the total nice size and there
+ // If there is more than the total preferred size and there
// are rubber bands, distribute surplus space among the
// rubber bands.
@@ -496,18 +508,18 @@
* We're in deep shit.
*
* Not only is there nothing to distribute among the weighted children,
- * we also need to resize the non-weighted children below their nice
+ * we also need to resize the non-weighted children below their preferred
* sizes. Let's at least treat them equally bad - divide the lost space
* among them as fair as possible.
*/
- long tooSmall = -distributableSize;
+ int tooSmall = -distributableSize;
int loserCount = 0;
- long totalMargins = 0L;
- long remainingMargins = 0L;
+ int totalMargins = 0L;
+ int remainingMargins = 0L;
double marginScale = 0.0;
- y2debug ( "Not enough space - %ld too small - check the layout!", tooSmall );
+ y2debug ( "Not enough space - %d too small - check the layout!", tooSmall );
// Maybe some of the children are YAlignments with margins that can be reduced
@@ -535,14 +547,14 @@
tooSmall = 0L;
marginScale = ( (double) remainingMargins ) / totalMargins;
- y2debug( "Making up for insufficient space by reducing margins to %.3g%% - %ld left for margins",
+ y2debug( "Making up for insufficient space by reducing margins to %.3g%% - %d left for margins",
100.0 * marginScale, remainingMargins );
}
else // Reducing all margins to zero still doesn't solve the problem
{
tooSmall -= totalMargins;
- y2debug( "Reducing all margins to 0, but still %ld too small", tooSmall );
+ y2debug( "Reducing all margins to 0, but still %d too small", tooSmall );
}
@@ -556,18 +568,18 @@
if ( ! (*it)->hasWeight( primary() ) )
{
loserCount++;
- childSize[i] = (*it)->nicesize( primary() );
+ childSize[i] = (*it)->preferredSize( primary() );
YAlignment * alignment = dynamic_cast<YAlignment *> (*it);
if ( alignment ) // Alignment widgets may have margins we can reduce
{
- long margins = alignment->totalMargins( primary() );
+ int margins = alignment->totalMargins( primary() );
childSize[i] -= margins; // Strip off original margin
if ( remainingMargins > 0 ) // Anything left to redistribute?
{
- margins = (long) ( marginScale * margins) ; // Scale down margin
+ margins = marginScale * margins; // Scale down margin
childSize[i] += margins; // Add the scaled-down margin
remainingMargins -= margins; // Deduct from redistributable margin
}
@@ -589,11 +601,11 @@
{
if ( debugLayout() )
{
- y2debug( "Distributing insufficient space of %ld amoung %d losers",
+ y2debug( "Distributing insufficient space of %d amoung %d losers",
tooSmall, loserCount );
}
- long dividedLoss = std::max( tooSmall / loserCount, 1L );
+ int dividedLoss = std::max( tooSmall / loserCount, 1L );
int i=0;
for ( YWidgetListConstIterator it = childrenBegin();
@@ -626,12 +638,12 @@
{
YWidget * child = *it;
- y2debug( "child #%d ( %s ) will get %ld - %ld too small "
- "(nice size: %ld, weight: %ld, stretchable: %s), pos %ld",
+ y2debug( "child #%d ( %s ) will get %d - %d too small "
+ "(preferred size: %d, weight: %d, stretchable: %s), pos %d",
i, child->widgetClass(),
childSize[i],
- child->nicesize( primary() ) - childSize[i],
- child->nicesize( primary() ),
+ child->preferredSize( primary() ) - childSize[i],
+ child->preferredSize( primary() ),
child->weight( primary() ),
child->stretchable( primary() ) ? "yes" : "no",
childPos[i] );
@@ -654,7 +666,7 @@
void
-YLayoutBox::calcSecondaryGeometry( long newSize,
+YLayoutBox::calcSecondaryGeometry( int newSize,
sizeVector & childSize,
posVector & childPos )
{
@@ -664,33 +676,33 @@
++it, i++ )
{
YWidget * child = *it;
- long nice = child->nicesize( secondary() );
+ int preferred = child->preferredSize( secondary() );
- if ( child->stretchable( secondary() ) || newSize < nice )
+ if ( child->stretchable( secondary() ) || newSize < preferred )
{
childSize[i] = newSize;
childPos [i] = 0L;
}
else // child is not stretchable and there is more space than it wants
{
- childSize[i] = nice;
- childPos [i] = ( newSize - nice ) / 2; // center
+ childSize[i] = preferred;
+ childPos [i] = ( newSize - preferred ) / 2; // center
}
- if ( childSize[i] < nice )
+ if ( childSize[i] < preferred )
{
- y2debug( "Resizing child widget #%d (%s) below its nice size of %ld to %ld "
+ y2debug( "Resizing child widget #%d (%s) below its preferred size of %d to %d "
"- check the layout!",
- i, child->widgetClass(), nice, childSize[i] );
+ i, child->widgetClass(), preferred, childSize[i] );
}
if ( debugLayout() )
{
- y2debug( "child #%d (%s) will get %ld "
- "(nice size: %ld, weight: %ld, stretchable: %s), pos %ld",
+ y2debug( "child #%d (%s) will get %d "
+ "(preferred size: %d, weight: %d, stretchable: %s), pos %d",
i, child->widgetClass(),
childSize[i],
- nice,
+ preferred,
child->weight( secondary() ),
child->stretchable( secondary() ) ? "yes" : "no",
childPos[i] );
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h?rev=39004&r1=39003&r2=39004&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h Mon Jun 25 16:33:55 2007
@@ -28,9 +28,10 @@
class YLayoutBox : public YWidget
{
public:
- typedef vector<long> sizeVector;
- typedef vector<long> posVector;
+ typedef vector<int> sizeVector;
+ typedef vector<int> posVector;
+protected:
/**
* Constructor.
*
@@ -38,6 +39,7 @@
**/
YLayoutBox( YWidget * parent, YUIDimension dim );
+public:
/**
* Destructor.
**/
@@ -76,35 +78,64 @@
* nice, i.e. all of the widget's preferred size.
*
* For the "primary" dimension, this is the sum of the children's
- * nice sizes with respect to any specified weight ratios -
+ * preferred sizes with respect to any specified weight ratios -
* i.e. the weights will always be respected. Children may be
* stretched as appropriate.
*
* For the "other" dimension, this is the maximum of the children's
- * nice sizes in that dimension.
+ * preferred sizes in that dimension.
*
* @param dim Dimension, either YD_HORIZ or YD_VERT
**/
- virtual long nicesize( YUIDimension dimension );
/**
- * The layout box is stretchable if one of the children is stretchable in
- * that dimension.
- * @param dim Dimension, either YD_HORIZ or YD_VERT
+ * Preferred size of the widget in the specified dimension.
+ *
+ * Reimplemented from YWidget.
**/
- virtual bool stretchable( YUIDimension dimension ) const;
+ virtual int preferredSize( YUIDimension dim );
/**
- * Sets the size of the layout box. Here the layout policy
- * is implemented. The ui specific widget must call this
- * method at the end of it's own setSize method.
+ * Preferred width of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- void setSize( long newwidth, long newheight );
+ virtual int preferredWidth();
/**
- * Moves a child to a new position
+ * Preferred height of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- virtual void moveChild( YWidget *child, long newx, long newy ) = 0;
+ virtual int preferredHeight();
+
+ /**
+ * Sets the size of the layout box. This is where the layout policy
+ * is implemented.
+ *
+ * Derived classes can reimplement this, but this base class method should
+ * be called in the reimplemented function.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual void setSize( int newWidth, int newHeight );
+
+ /**
+ * Returns the stretchability of the layout box:
+ * The layout box is stretchable if one of the children is stretchable in
+ * this dimension or if one of the child widgets has a layout weight in
+ * this dimension.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual bool stretchable( YUIDimension dimension ) const;
+
+ /**
+ * Move a child to a new position.
+ *
+ * Derived classes are required to implement this.
+ **/
+ virtual void moveChild( YWidget * child, int newX, int newY ) = 0;
protected:
@@ -112,17 +143,19 @@
/**
* Add up all the children's weights.
**/
- long childrenTotalWeight( YUIDimension dimension );
+ int childrenTotalWeight( YUIDimension dimension );
- /**
- * Return the maximum nice size of all children in dimension d.
+ /**
+ * Return the maximum preferred size of all children in the specified
+ * dimension.
**/
- long childrenMaxNiceSize( YUIDimension dimension );
+ int childrenMaxPreferredSize( YUIDimension dimension );
/**
- * Add up all the non-weighted children's nice sizes in dimension d.
+ * Add up all the non-weighted children's preferred sizes in the specified
+ * dimension.
**/
- long totalNonWeightedChildrenNiceSize( YUIDimension dimension );
+ int totalNonWeightedChildrenPreferredSize( YUIDimension dimension );
/**
* Count the number of non-weighted children.
@@ -161,7 +194,7 @@
* Calculate the sizes and positions of all children in the primary
* dimension and store them in "childSize" and "childPos".
**/
- void calcPrimaryGeometry ( long newSize,
+ void calcPrimaryGeometry ( int newSize,
sizeVector & childSize,
posVector & childPos );
@@ -169,7 +202,7 @@
* Calculate the sizes and positions of all children in the secondary
* dimension and store them in "childSize" and "childPos".
**/
- void calcSecondaryGeometry ( long newSize,
+ void calcSecondaryGeometry ( int newSize,
sizeVector & childSize,
posVector & childPos );
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx
Date: Mon Jun 25 16:33:55 2007
New Revision: 39004
URL: http://svn.opensuse.org/viewcvs/yast?rev=39004&view=rev
Log:
ported to preferredWidth() / -Height()
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc
branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc?rev=39004&r1=39003&r2=39004&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.cc Mon Jun 25 16:33:55 2007
@@ -96,12 +96,12 @@
}
-long
-YLayoutBox::nicesize( YUIDimension dimension )
+void
+YLayoutBox::preferredSize( YUIDimension dimension )
{
if ( dimension == secondary() ) // the easy case first: secondary dimension
{
- return childrenMaxNiceSize( dimension );
+ return childrenMaxPreferredSize( dimension );
}
else
{
@@ -113,11 +113,11 @@
* know that, we need to stretch all other weighted children accordingly
* so the weight ratios are respected.
*
- * As a final step, the nice sizes of all children that don't have
+ * As a final step, the preferred sizes of all children that don't have
* a weight attached are summed up.
*/
- long size = 0L;
+ int size = 0L;
// Search for the dominating child
YWidget * dominatingChild = findDominatingChild();
@@ -126,7 +126,7 @@
{
// Calculate size of all weighted widgets.
- size = dominatingChild->nicesize( primary() )
+ size = dominatingChild->preferredSize( primary() )
* childrenTotalWeight( primary() )
/ dominatingChild->weight( primary() );
@@ -136,21 +136,33 @@
// Add up the size of all non-weighted children;
- // they will get their respective nice size.
+ // they will get their respective preferred size.
- size += totalNonWeightedChildrenNiceSize( primary() );
+ size += totalNonWeightedChildrenPreferredSize( primary() );
return size;
}
}
+int YLayoutBox::preferredWidth()
+{
+ return preferredSize( YD_HORIZ );
+}
+
+
+int YLayoutBox::preferredHeight()
+{
+ return preferredSize( YD_VERT );
+}
+
+
/*
* Search for the "dominating child" widget.
*
* This is the widget that determines the overall size of the
* container with respect to all children's weights: It is the child
- * with the maximum ratio of nice size and weight. All other
+ * with the maximum ratio of preferred size and weight. All other
* weighted children need to be stretched accordingly so the weight
* ratios can be maintained.
*
@@ -173,7 +185,7 @@
if ( child->weight( primary() ) != 0 ) // avoid division by zero
{
- ratio = ( ( double ) child->nicesize( primary() ) )
+ ratio = ( ( double ) child->preferredSize( primary() ) )
/ child->weight( primary() );
if ( ratio > dominatingRatio ) // we have a new dominating child
@@ -190,9 +202,9 @@
if ( dominatingChild >= 0 )
{
y2debug( "YLayoutBox::findDominatingChild(): "
- "Found dominating child: %s - nice size: %ld, weight: %ld",
+ "Found dominating child: %s - preferred size: %d, weight: %d",
dominatingChild->widgetClass(),
- dominatingChild->nicesize( primary() ),
+ dominatingChild->preferredSize( primary() ),
dominatingChild->weight( primary() ) );
}
else
@@ -206,26 +218,26 @@
}
-long
-YLayoutBox::childrenMaxNiceSize( YUIDimension dimension )
+int
+YLayoutBox::childrenMaxPreferredSize( YUIDimension dimension )
{
- long maxNiceSize = 0L;
+ int maxPreferredSize = 0L;
for ( YWidgetListConstIterator it = childrenBegin();
it != childrenEnd();
++it )
{
- maxNiceSize = std::max( (*it)->nicesize( dimension ), maxNiceSize );
+ maxPreferredSize = std::max( (*it)->preferredSize( dimension ), maxPreferredSize );
}
- return maxNiceSize;
+ return maxPreferredSize;
}
-long
+int
YLayoutBox::childrenTotalWeight( YUIDimension dimension )
{
- long totalWeight = 0L;
+ int totalWeight = 0L;
for ( YWidgetListConstIterator it = childrenBegin();
it != childrenEnd();
@@ -238,17 +250,17 @@
}
-long
-YLayoutBox::totalNonWeightedChildrenNiceSize( YUIDimension dimension )
+int
+YLayoutBox::totalNonWeightedChildrenPreferredSize( YUIDimension dimension )
{
- long size = 0L;
+ int size = 0L;
for ( YWidgetListConstIterator it = childrenBegin();
it != childrenEnd();
++it )
{
if ( ! (*it)->hasWeight( dimension ) ) // non-weighted children only
- size += (*it)->nicesize( dimension );
+ size += (*it)->preferredSize( dimension );
}
return size;
@@ -341,7 +353,7 @@
void
-YLayoutBox::setSize( long newWidth, long newHeight )
+YLayoutBox::setSize( int newWidth, int newHeight )
{
int count = childrenCount();
sizeVector widths ( count );
@@ -374,24 +386,24 @@
void
-YLayoutBox::calcPrimaryGeometry( long newSize,
+YLayoutBox::calcPrimaryGeometry( int newSize,
sizeVector & childSize,
posVector & childPos )
{
- long pos = 0L;
- long distributableSize = newSize - totalNonWeightedChildrenNiceSize( primary() );
+ int pos = 0L;
+ int distributableSize = newSize - totalNonWeightedChildrenPreferredSize( primary() );
if ( distributableSize >= 0L )
{
// The (hopefully) normal case: There is enough space.
- // The non-weighted children will get their nice sizes,
+ // The non-weighted children will get their preferred sizes,
// the rest will be distributed among the weighted children
// according to their respective weight ratios.
- long nonWeightedExtra = 0L;
- long totalWeight = childrenTotalWeight( primary() );
+ int nonWeightedExtra = 0L;
+ int totalWeight = childrenTotalWeight( primary() );
int rubberBands = 0;
- long rubberBandExtra = 0L;
+ int rubberBandExtra = 0L;
if ( totalWeight <= 0 )
{
@@ -408,14 +420,14 @@
{
// If there are weighted children and there are rubber band
// widgets, equally divide any surplus space (i.e. space that
- // exceeds the weighted children's nice sizes with respect to
+ // exceeds the weighted children's preferred sizes with respect to
// their weights) between the rubber bands.
//
- // This offers an easy way to make nice even spaced buttons
+ // This offers an easy way to make nicely even spaced buttons
// of equal size: Give all buttons a weight of 1 and insert a
// stretch (without weight!) between each.
- long surplusSize = newSize - nicesize( primary() );
+ int surplusSize = newSize - preferredSize( primary() );
if ( surplusSize > 0L )
{
@@ -432,12 +444,12 @@
if ( debugLayout() )
{
y2debug( "Distributing extra space" );
- y2debug( "new size: %ld", newSize );
- y2debug( "distributable size: %ld", distributableSize );
- y2debug( "rubber band extra: %ld", rubberBandExtra );
+ y2debug( "new size: %d", newSize );
+ y2debug( "distributable size: %d", distributableSize );
+ y2debug( "rubber band extra: %d", rubberBandExtra );
y2debug( "rubber bands: %d", rubberBands );
- y2debug( "total weight: %ld", totalWeight );
- y2debug( "non weighted extra: %ld", nonWeightedExtra );
+ y2debug( "total weight: %d", totalWeight );
+ y2debug( "non weighted extra: %d", nonWeightedExtra );
}
int i=0;
@@ -453,18 +465,18 @@
childSize[i] = distributableSize * child->weight( primary() ) / totalWeight;
- if ( childSize[i] < child->nicesize( primary() ) )
+ if ( childSize[i] < child->preferredSize( primary() ) )
{
- y2debug( "Resizing child widget #%d (%s) below its nice size of %ld to %ld "
+ y2debug( "Resizing child widget #%d (%s) below its preferred size of %d to %d "
"- check the layout!",
- i, child->widgetClass(), child->nicesize( primary() ), childSize[i] );
+ i, child->widgetClass(), child->preferredSize( primary() ), childSize[i] );
}
}
else
{
- // Non-weighted children will get their nice size.
+ // Non-weighted children will get their preferred size.
- childSize[i] = child->nicesize( primary() );
+ childSize[i] = child->preferredSize( primary() );
if ( child->stretchable( primary() ) )
@@ -478,7 +490,7 @@
if ( isLayoutStretch( child, primary() ) )
{
- // If there is more than the total nice size and there
+ // If there is more than the total preferred size and there
// are rubber bands, distribute surplus space among the
// rubber bands.
@@ -496,18 +508,18 @@
* We're in deep shit.
*
* Not only is there nothing to distribute among the weighted children,
- * we also need to resize the non-weighted children below their nice
+ * we also need to resize the non-weighted children below their preferred
* sizes. Let's at least treat them equally bad - divide the lost space
* among them as fair as possible.
*/
- long tooSmall = -distributableSize;
+ int tooSmall = -distributableSize;
int loserCount = 0;
- long totalMargins = 0L;
- long remainingMargins = 0L;
+ int totalMargins = 0L;
+ int remainingMargins = 0L;
double marginScale = 0.0;
- y2debug ( "Not enough space - %ld too small - check the layout!", tooSmall );
+ y2debug ( "Not enough space - %d too small - check the layout!", tooSmall );
// Maybe some of the children are YAlignments with margins that can be reduced
@@ -535,14 +547,14 @@
tooSmall = 0L;
marginScale = ( (double) remainingMargins ) / totalMargins;
- y2debug( "Making up for insufficient space by reducing margins to %.3g%% - %ld left for margins",
+ y2debug( "Making up for insufficient space by reducing margins to %.3g%% - %d left for margins",
100.0 * marginScale, remainingMargins );
}
else // Reducing all margins to zero still doesn't solve the problem
{
tooSmall -= totalMargins;
- y2debug( "Reducing all margins to 0, but still %ld too small", tooSmall );
+ y2debug( "Reducing all margins to 0, but still %d too small", tooSmall );
}
@@ -556,18 +568,18 @@
if ( ! (*it)->hasWeight( primary() ) )
{
loserCount++;
- childSize[i] = (*it)->nicesize( primary() );
+ childSize[i] = (*it)->preferredSize( primary() );
YAlignment * alignment = dynamic_cast<YAlignment *> (*it);
if ( alignment ) // Alignment widgets may have margins we can reduce
{
- long margins = alignment->totalMargins( primary() );
+ int margins = alignment->totalMargins( primary() );
childSize[i] -= margins; // Strip off original margin
if ( remainingMargins > 0 ) // Anything left to redistribute?
{
- margins = (long) ( marginScale * margins) ; // Scale down margin
+ margins = marginScale * margins; // Scale down margin
childSize[i] += margins; // Add the scaled-down margin
remainingMargins -= margins; // Deduct from redistributable margin
}
@@ -589,11 +601,11 @@
{
if ( debugLayout() )
{
- y2debug( "Distributing insufficient space of %ld amoung %d losers",
+ y2debug( "Distributing insufficient space of %d amoung %d losers",
tooSmall, loserCount );
}
- long dividedLoss = std::max( tooSmall / loserCount, 1L );
+ int dividedLoss = std::max( tooSmall / loserCount, 1L );
int i=0;
for ( YWidgetListConstIterator it = childrenBegin();
@@ -626,12 +638,12 @@
{
YWidget * child = *it;
- y2debug( "child #%d ( %s ) will get %ld - %ld too small "
- "(nice size: %ld, weight: %ld, stretchable: %s), pos %ld",
+ y2debug( "child #%d ( %s ) will get %d - %d too small "
+ "(preferred size: %d, weight: %d, stretchable: %s), pos %d",
i, child->widgetClass(),
childSize[i],
- child->nicesize( primary() ) - childSize[i],
- child->nicesize( primary() ),
+ child->preferredSize( primary() ) - childSize[i],
+ child->preferredSize( primary() ),
child->weight( primary() ),
child->stretchable( primary() ) ? "yes" : "no",
childPos[i] );
@@ -654,7 +666,7 @@
void
-YLayoutBox::calcSecondaryGeometry( long newSize,
+YLayoutBox::calcSecondaryGeometry( int newSize,
sizeVector & childSize,
posVector & childPos )
{
@@ -664,33 +676,33 @@
++it, i++ )
{
YWidget * child = *it;
- long nice = child->nicesize( secondary() );
+ int preferred = child->preferredSize( secondary() );
- if ( child->stretchable( secondary() ) || newSize < nice )
+ if ( child->stretchable( secondary() ) || newSize < preferred )
{
childSize[i] = newSize;
childPos [i] = 0L;
}
else // child is not stretchable and there is more space than it wants
{
- childSize[i] = nice;
- childPos [i] = ( newSize - nice ) / 2; // center
+ childSize[i] = preferred;
+ childPos [i] = ( newSize - preferred ) / 2; // center
}
- if ( childSize[i] < nice )
+ if ( childSize[i] < preferred )
{
- y2debug( "Resizing child widget #%d (%s) below its nice size of %ld to %ld "
+ y2debug( "Resizing child widget #%d (%s) below its preferred size of %d to %d "
"- check the layout!",
- i, child->widgetClass(), nice, childSize[i] );
+ i, child->widgetClass(), preferred, childSize[i] );
}
if ( debugLayout() )
{
- y2debug( "child #%d (%s) will get %ld "
- "(nice size: %ld, weight: %ld, stretchable: %s), pos %ld",
+ y2debug( "child #%d (%s) will get %d "
+ "(preferred size: %d, weight: %d, stretchable: %s), pos %d",
i, child->widgetClass(),
childSize[i],
- nice,
+ preferred,
child->weight( secondary() ),
child->stretchable( secondary() ) ? "yes" : "no",
childPos[i] );
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h?rev=39004&r1=39003&r2=39004&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YLayoutBox.h Mon Jun 25 16:33:55 2007
@@ -28,9 +28,10 @@
class YLayoutBox : public YWidget
{
public:
- typedef vector<long> sizeVector;
- typedef vector<long> posVector;
+ typedef vector<int> sizeVector;
+ typedef vector<int> posVector;
+protected:
/**
* Constructor.
*
@@ -38,6 +39,7 @@
**/
YLayoutBox( YWidget * parent, YUIDimension dim );
+public:
/**
* Destructor.
**/
@@ -76,35 +78,64 @@
* nice, i.e. all of the widget's preferred size.
*
* For the "primary" dimension, this is the sum of the children's
- * nice sizes with respect to any specified weight ratios -
+ * preferred sizes with respect to any specified weight ratios -
* i.e. the weights will always be respected. Children may be
* stretched as appropriate.
*
* For the "other" dimension, this is the maximum of the children's
- * nice sizes in that dimension.
+ * preferred sizes in that dimension.
*
* @param dim Dimension, either YD_HORIZ or YD_VERT
**/
- virtual long nicesize( YUIDimension dimension );
/**
- * The layout box is stretchable if one of the children is stretchable in
- * that dimension.
- * @param dim Dimension, either YD_HORIZ or YD_VERT
+ * Preferred size of the widget in the specified dimension.
+ *
+ * Reimplemented from YWidget.
**/
- virtual bool stretchable( YUIDimension dimension ) const;
+ virtual int preferredSize( YUIDimension dim );
/**
- * Sets the size of the layout box. Here the layout policy
- * is implemented. The ui specific widget must call this
- * method at the end of it's own setSize method.
+ * Preferred width of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- void setSize( long newwidth, long newheight );
+ virtual int preferredWidth();
/**
- * Moves a child to a new position
+ * Preferred height of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- virtual void moveChild( YWidget *child, long newx, long newy ) = 0;
+ virtual int preferredHeight();
+
+ /**
+ * Sets the size of the layout box. This is where the layout policy
+ * is implemented.
+ *
+ * Derived classes can reimplement this, but this base class method should
+ * be called in the reimplemented function.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual void setSize( int newWidth, int newHeight );
+
+ /**
+ * Returns the stretchability of the layout box:
+ * The layout box is stretchable if one of the children is stretchable in
+ * this dimension or if one of the child widgets has a layout weight in
+ * this dimension.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual bool stretchable( YUIDimension dimension ) const;
+
+ /**
+ * Move a child to a new position.
+ *
+ * Derived classes are required to implement this.
+ **/
+ virtual void moveChild( YWidget * child, int newX, int newY ) = 0;
protected:
@@ -112,17 +143,19 @@
/**
* Add up all the children's weights.
**/
- long childrenTotalWeight( YUIDimension dimension );
+ int childrenTotalWeight( YUIDimension dimension );
- /**
- * Return the maximum nice size of all children in dimension d.
+ /**
+ * Return the maximum preferred size of all children in the specified
+ * dimension.
**/
- long childrenMaxNiceSize( YUIDimension dimension );
+ int childrenMaxPreferredSize( YUIDimension dimension );
/**
- * Add up all the non-weighted children's nice sizes in dimension d.
+ * Add up all the non-weighted children's preferred sizes in the specified
+ * dimension.
**/
- long totalNonWeightedChildrenNiceSize( YUIDimension dimension );
+ int totalNonWeightedChildrenPreferredSize( YUIDimension dimension );
/**
* Count the number of non-weighted children.
@@ -161,7 +194,7 @@
* Calculate the sizes and positions of all children in the primary
* dimension and store them in "childSize" and "childPos".
**/
- void calcPrimaryGeometry ( long newSize,
+ void calcPrimaryGeometry ( int newSize,
sizeVector & childSize,
posVector & childPos );
@@ -169,7 +202,7 @@
* Calculate the sizes and positions of all children in the secondary
* dimension and store them in "childSize" and "childPos".
**/
- void calcSecondaryGeometry ( long newSize,
+ void calcSecondaryGeometry ( int newSize,
sizeVector & childSize,
posVector & childPos );
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx
| < Previous | Next > |