Ejemplo n.º 1
0
int HTMLTableCell::calcMinWidth()
{
    HTMLObject *obj;
    int minWidth = 0;

    for ( obj = head; obj != 0; obj = obj->next() )
    {
	int w = obj->calcMinWidth();
	if ( w > minWidth )
	    minWidth = w;
    }

    if ( isFixedWidth() )
    {
        // Our minimum width is at least our fixed width
        if (max_width > minWidth)
            minWidth = max_width;

        // And our actual width is at least our minimum width.
        if (width < minWidth)
            width = minWidth;
    }
                                                                    
    return minWidth;
}
Ejemplo n.º 2
0
// Use the minimum and preferred cell widths to produce an optimum
// cell spacing.  When this has been done columnOpt contains
// the optimum cell widths.
void HTMLTable::optimiseCellWidth()
{
    int tableWidth = width - border;
    int addSize = 0;
	
    columnOpt = columnPos.copy();

    if (tableWidth > columnPos[ totalCols ] )
    {
	// We have some space to spare
	addSize = tableWidth - columnPos[ totalCols];

	if ((percent <= 0) && (!isFixedWidth()))
	{
	    // Variable width Table, 
	    if (columnPrefPos[totalCols] < tableWidth)
	    {
	        // don't scale beyond preferred width.
	        addSize = columnPrefPos[totalCols] - 
	                  columnPos[ totalCols];
	    }
	}
    }
    
    if (addSize > 0)
    {
        scaleColumns(0, totalCols-1, addSize);
    }
}
Ejemplo n.º 3
0
//--------------------------------------------------------------
// for setting the content box when the width and/or height are fixed
float ofxMuiBox::getMaxAllowableContentBoxWidth() const {
    if(isFixedWidth()) {
        return getWidth() - getContentBoxSideOffset(SIDE_LEFT) - getContentBoxSideOffset(SIDE_RIGHT);
    } else {
        return numeric_limits<float>::max();
    }
}
Ejemplo n.º 4
0
void HTMLTableCell::setWidth(int _width)
{
    HTMLObject *obj;

    width = _width;
    if(!isFixedWidth())
	max_width = width;

    for ( obj = head; obj != 0; obj = obj->next() )
	obj->setMaxWidth( width );
}
Ejemplo n.º 5
0
void HTMLTable::setMaxWidth( int _max_width )
{
    max_width = _max_width;
    if (!isFixedWidth())
    {
        if ( percent > 0 )
            width = max_width * percent / 100;
        else 
            width = max_width;
        calcColumnWidths();
    }
}
Ejemplo n.º 6
0
//--------------------------------------------------------------
void ofxMuiBox::setContentBoxWidth(float _width) {
    if(_width < 0) {
        ofLog(OF_LOG_ERROR,"ofxMuiBox: Set a negative content box width.  Not possible.");
        return;
    }
    
    if(isFixedWidth()) {
        contentBox.width = getWidth() - getContentBoxSideOffset(SIDE_LEFT) - getContentBoxSideOffset(SIDE_RIGHT);
    } else {
        contentBox.width = _width;
    }
    
}
Ejemplo n.º 7
0
void HTMLClueV::setMaxWidth( int _max_width )
{
    HTMLObject *obj;

    if ( !isFixedWidth() )
    {
	max_width = _max_width;
	if ( percent > 0 )
	    width = _max_width * percent / 100;
	else
	    width = max_width;
    }

    for ( obj = head; obj != 0; obj = obj->next() )
	obj->setMaxWidth( width );
}
Ejemplo n.º 8
0
void HTMLTableCell::setMaxWidth( int _max_width )
{
    HTMLObject *obj;

    max_width = _max_width;

    if (max_width > 0)
    {
	if ( percent > 0 )
            width = _max_width * percent / 100;
	else if ( !isFixedWidth() )
	    width = max_width;
    }

    for ( obj = head; obj != 0; obj = obj->next() )
	obj->setMaxWidth( max_width );
}
Ejemplo n.º 9
0
int HTMLClue::calcPreferredWidth()
{
    if ( isFixedWidth() )
	return width;

    HTMLObject *obj;
    int prefWidth = 0;

    for ( obj = head; obj != 0; obj = obj->next() )
    {
	int w = obj->calcPreferredWidth();
	if ( w > prefWidth )
	    prefWidth = w;
    }

    return prefWidth;
}
Ejemplo n.º 10
0
int HTMLClue::calcMinWidth()
{
    HTMLObject *obj;
    int minWidth = 0;

    for ( obj = head; obj != 0; obj = obj->next() )
    {
	int w = obj->calcMinWidth();
	if ( w > minWidth )
	    minWidth = w;
    }

    if ( isFixedWidth() )
    {
        if (width > minWidth)
            minWidth = width;
    }

    return minWidth;
}
Ejemplo n.º 11
0
// New table layout function
//
// Both the minimum and preferred column sizes are calculated here.
// The hard part is choosing the actual sizes based on these two.
void HTMLTable::calcColInfo()
{
    unsigned int r, c;
    int borderExtra = ( border == 0 ) ? 0 : 1;

    // Allocate some memory for column info
    colInfo.resize( totalCols*2 );
    rowInfo = (RowInfo_t *) malloc( totalRows * sizeof(RowInfo_t) );
    totalColInfos = 0;
    
    for ( r = 0; r < totalRows; r++ )
    {
	rowInfo[r].entry = (int *) malloc( totalCols * sizeof(int));
	rowInfo[r].nrEntries = 0;
        for ( c = 0; c < totalCols; c++ )
	{
	    HTMLTableCell *cell = cells[r][c];
	    int            min_size;
	    int            pref_size;
	    int            colInfoIndex;
	    ColType        col_type;

	    if ( cell == 0 )
		continue; 
	    if ( (c > 0) && (cells[r][c-1] == cell) )
		continue;
	    if ( (r > 0) && (cells[r-1][c] == cell) )
		continue;

	    // calculate minimum size
	    min_size = cell->calcMinWidth() + padding + padding + 
	              spacing + borderExtra;

	    // calculate preferred pos
	    if ( cell->getPercent() > 0 )
	    {
		pref_size = ( max_width * cell->getPercent() / 100 ) + 
		           padding + padding + spacing + borderExtra;
		col_type = Percent;
	    }
	    else if ( cell->isFixedWidth() )
	    {
		pref_size = cell->getWidth() + padding + padding + 
		            spacing + borderExtra;
		col_type = Fixed;
	    }
	    else
	    {
		pref_size = cell->calcPreferredWidth() + 
		            padding + padding + spacing + borderExtra;
		col_type = Variable;
	    }
	    colInfoIndex = addColInfo(c, cell->colSpan(), min_size, 
	                              pref_size, max_width, col_type);
	    addRowInfo(r, colInfoIndex);
	}
    }

    // Remove redundant rows
    unsigned int i;
    unsigned int totalRowInfos;
    totalRowInfos = 1;
    for(i = 1; i < totalRows; i++)
    {
    	bool unique = TRUE;
    	for(unsigned int j = 0; (j < totalRowInfos) && (unique == TRUE); j++)
    	{
    	    unsigned k;
    	    if (rowInfo[i].nrEntries == rowInfo[j].nrEntries)
    	        unique = FALSE;
    	    else
    	    {
    	        bool match = TRUE;
    	        k = rowInfo[i].nrEntries;
    	        while (k--)
    	        {
    	            if (rowInfo[i].entry[k] != rowInfo[j].entry[k])
    	            {
    	            	match = FALSE;
    	            	break;
    	            }
    	        }
    	        if (match)
    	            unique = FALSE;
    	    }
    	}
    	if (!unique)
    	{
    	     free( rowInfo[i].entry);
    	}
    	else 
    	{
    	    if (totalRowInfos != i)
    	    {
    	        rowInfo[totalRowInfos].entry = rowInfo[i].entry;
    	        rowInfo[totalRowInfos].nrEntries = rowInfo[i].nrEntries;
    	    }
    	    totalRowInfos++;
    	}
    }

    // Calculate pref width and min width for each row
    
    _minWidth = 0;
    _prefWidth = 0;
    for(i = 0; i < totalRowInfos; i++)
    {
        int min = 0;
        int pref = 0;
        for(int j = 0; j < rowInfo[i].nrEntries; j++)
        {
           int index = rowInfo[i].entry[j];
           min += colInfo[index].minSize;
           pref += colInfo[index].prefSize;
	}
	rowInfo[i].minSize = min;
	rowInfo[i].prefSize = pref;
	if (_minWidth < min)
	{
	    _minWidth = min;
	}
	if (_prefWidth < pref)
	{
	    _prefWidth = pref;
	}
    }

    if ( isFixedWidth() )
    {
        // Our minimum width is at least our fixed width
        if (width > _minWidth)
            _minWidth = width;

        // And our actual width is at least our minimum width.
        if (width < _minWidth)
            width = _minWidth;
    }
    
    // DEBUG: Show the results :)
#if 0    
    //printf("---- %d ----\n", totalColInfos);
    for(i = 0; i < totalColInfos; i++)
    {
        //printf("col #%d: %d - %d, min: %3d pref: %3d max: %3d type: %d\n",
                 i,
                 colInfo[i].startCol, colInfo[i].colSpan,
                 colInfo[i].minSize, colInfo[i].prefSize,
                 colInfo[i].maxSize, (int) colInfo[i].colType);
    }
    for(i = 0; i < totalRowInfos; i++)
    {
        //printf("row #%d: ", i);
        for(j = 0; j < rowInfo[i].nrEntries; j++)
        {
           if (j == 0)
              //printf("%d", rowInfo[i].entry[j]);
           else
              //printf("- %d", rowInfo[i].entry[j]);
        } 
        //printf(" ! %d : %d\n", rowInfo[i].minSize, rowInfo[i].prefSize);
    }
#endif
}
Ejemplo n.º 12
0
int HTMLClueFlow::calcMinWidth()
{
#if 1
    HTMLObject *obj;
    int minWidth = 0;

    for ( obj = head; obj != 0; obj = obj->next() )
    {
	int w = obj->calcMinWidth();
	if ( w > minWidth )
	    minWidth = w;
    }
	
    minWidth += indent;	

    if ( isFixedWidth() )
    {
        if (width > minWidth)
            minWidth = width;
    }

    return minWidth;
#else
    HTMLObject *obj = head;
    int minWidth = 0;
    int ow, runWidth = 0;

    while ( obj )
    {
	if ( obj->isSeparator() || obj->isNewline() )
	{
	    ow = obj->calcMinWidth();

	    runWidth += ow;

	    if ( runWidth > minWidth )
                minWidth = runWidth;

	    runWidth = 0;
	}
	else
	{
	    ow = obj->calcMinWidth();

	    // we try not to grow larger than max_width by breaking at
	    // object boundaries if necessary.
	    if ( runWidth + ow > max_width )
		runWidth = 0;

	    runWidth += ow;

	    if ( runWidth > minWidth )
		minWidth = runWidth;
	}

	obj = obj->next();
    }

    if ( isFixedWidth() )
    {
    	if (width > minWidth)
            minWidth = width;
    }

    return minWidth + indent;
#endif
}