private float getLineHeight(CSReportDll.cReportPageFields fields, ref float[] offsetTop)
{
CSReportDll.cReportPageField field = null;
float offBottom = 0;
float aspectHeight = 0;
float aspectWidth = 0;
CSReportDll.cReportAspect aspect = null;
CSReportDll.cReportAspect aspectLn = null;
// used to get the offset to top
//
float lnHeight = 0;
// used to increase the height of the line
//
float lnHeight2 = 0;
float newLnHeight = 0;
Font font = null;
float topSection = 0;
int indexSection = -1;
float heightSection = 0;
offsetTop = new float[1];
if (fields.count() > 0)
{
// search for the highest control
//
for (int _i = 0; _i < fields.count(); _i++)
{
field = fields.item(_i);
// if it can grow we need to get its height to be
// able to print it
//
aspect = field.getInfo().getAspect();
aspectLn = field.getInfo().getSectionLine().getAspect();
// TODO: remove me
// System.Console.WriteLine(field.getInfo().getSectionLine().getRealIndex());
// if the line has changed we need to get the height of the line
// and add it to heightSection
//
if (indexSection != field.getInfo().getSectionLine().getIndex())
{
// save a reference to this section
//
indexSection = field.getInfo().getSectionLine().getIndex();
if (indexSection > offsetTop.Length -1)
{
G.redimPreserve(ref offsetTop, indexSection + 1);
}
// save this offset to add it to every control holded in the
// section lines which are under the current section line
//
offsetTop[indexSection] = offsetTop[indexSection] + newLnHeight - lnHeight;
// we get the top of the current line which includes only
// the height of visible lines
//
topSection = topSection + (aspectLn.getTop() - (topSection + heightSection));
// add to heightSection the height of this line
//
heightSection = heightSection + aspectLn.getHeight();
// save the height of the line to know if it has changed for canGrow
//
lnHeight = aspectLn.getHeight();
// the height of the original section line
//
lnHeight2 = lnHeight;
// save the height of the line to analize canGrow
//
newLnHeight = lnHeight;
}
// add to every control the offset produced by controls which
// can grow
//
if (aspect.getCanGrow())
{
aspectHeight = aspect.getHeight();
aspectWidth = aspect.getWidth();
// if there is an image we need to get its height
//
if (field.getImage() != null)
{
int imgWidth = 0;
int imgHeight = 0;
cGlobals.getBitmapSize(field.getImage(), out imgWidth, out imgHeight, true);
field.setHeight(imgHeight);
field.setWidth(imgWidth);
if (field.getHeight() < aspectHeight) { field.setHeight(aspectHeight); }
if (field.getWidth() < aspectWidth) { field.setWidth(aspectWidth); }
}
else
{
if (field.getValue() != "")
{
int flags = 0;
// TODO: flags to get height of text to be drawn
if (aspect.getWordWrap())
{
flags = 0/*ECGTextAlignFlags.DT_WORDBREAK
|| ECGTextAlignFlags.DT_WORD_ELLIPSIS
|| ECGTextAlignFlags.DT_LEFT
|| ECGTextAlignFlags.DT_NOPREFIX
|| ECGTextAlignFlags.DT_EDITCONTROL*/;
}
else
{
flags = 0/*ECGTextAlignFlags.DT_SINGLELINE
|| ECGTextAlignFlags.DT_WORD_ELLIPSIS
|| ECGTextAlignFlags.DT_LEFT
|| ECGTextAlignFlags.DT_NOPREFIX*/;
}
int idx = cGlobals.addFontIfRequired(aspect.getFont(), ref m_fnt);
font = m_fnt[idx];
field.setHeight(
evaluateTextHeight(
field.getValue(),
font,
aspect.getWidth(),
flags,
m_scaleY,
m_scaleX));
if (field.getHeight() < aspectHeight) { field.setHeight(aspectHeight); }
}
}
// if it doesn't fit in the line because is too high
//
if (field.getHeight() + aspect.getTop() > topSection + newLnHeight)
{
offBottom = (topSection + newLnHeight) - (aspect.getTop() + aspectHeight);
// to separete a little
//
if (offBottom < 0) { offBottom = offBottom + 5; }
// new line's height
//
newLnHeight = aspect.getTop() - topSection + field.getHeight() + offBottom;
}
// if the height of the previous line has changed because
// some control has set to canGrow = true and its value
// makes the control's height to change, we need to add
// this height to heightSection
//
if (newLnHeight > lnHeight2)
{
// substract the original height
// | add the hieght for canGrow
// | |
heightSection = heightSection - lnHeight2 + newLnHeight;
lnHeight2 = newLnHeight;
}
}
else
{
field.setHeight(aspect.getHeight());
}
}
}
// return the height of the section
//
return heightSection;
}