int ControlLayoutHelper::CalculateHeaderTextHeight(CWnd& calculateWnd)
{
	if(calculateWnd.GetSafeHwnd() == NULL)
		return 0;
	
	CDC* pDC = calculateWnd.GetWindowDC();

	CRect groupRect(0,0,0,0);

	if(NULL != pDC)
	{
		CString wndText;
		calculateWnd.GetWindowText(wndText);

		pDC->DrawText(wndText, &groupRect, DT_CALCRECT);
	}

	return groupRect.Height();
}
/**
 * Calculates the classifier box dimensions and the position of text
 * items inside it based on the current size.
 *
 * @note Assumes calculateTemplateDrawing is called before calling
 *       this method.
 */
void ClassifierWidget::calculateClassifierDrawing()
{
    const qreal w = width();
    const qreal h = height();

    TextItemGroup *headerGroup = textItemGroupAt(HeaderGroupIndex);
    TextItemGroup *attribOpGroup = textItemGroupAt(AttribOpGroupIndex);

    if (shouldDrawAsCircle()) {
        // Allocates circle space algined at top and "minimum space"
        // for the text which is aligned bottom.
        qreal fontHeight = headerGroup->minimumSize().height();
        qreal diameter = qMin(w, h - fontHeight);
        m_classifierRect.setRect(0, 0, diameter, diameter);
        m_classifierRect.moveCenter(QPointF(.5 * w, m_classifierRect.center().y()));

        QRectF groupRect(0, diameter, w, h - diameter);
        headerGroup->setGroupGeometry(groupRect);
        // classifierGroup->setGroupGeometry(groupRect);
        m_classifierLines[0] = m_classifierLines[1] = QLineF();
    }
    else {
        // Utilize entire space if template box is empty.
        if (textItemGroupAt(TemplateGroupIndex)->textItemCount() == 0) {
            m_classifierRect = rect();
        }
        else {
            m_classifierRect.setTop(m_templateRect.bottom() - margin());
            m_classifierRect.setLeft(0);
            m_classifierRect.setBottomRight(QPointF(m_templateRect.center().x(), h));
        }

        QRectF headerGeometry(m_classifierRect);
        headerGeometry.setHeight(headerGroup->minimumSize().height());
        headerGroup->setGroupGeometry(headerGeometry);

        QRectF attribOpGeometry(m_classifierRect);
        attribOpGeometry.setTop(headerGeometry.bottom());
        attribOpGroup->setGroupGeometry(attribOpGeometry);

        const int cnt = attribOpGroup->textItemCount();
        qreal expanderDistance = -11;
        bool showNameOnly = (!visualProperty(ShowAttributes) && !visualProperty(ShowOperations)
                && !visualProperty(ShowStereotype) && !shouldDrawAsCircle());
        if (!showNameOnly && !shouldDrawAsCircle()) {
            qreal y = textItemGroupAt(HeaderGroupIndex)->groupGeometry().bottom();
            m_classifierLines[0].setLine(m_classifierRect.left(), y, m_classifierRect.right(), y);
            qreal expanderX = rect().left() -
                m_attributeExpanderBox->rect().width() - expanderDistance;
            m_attributeExpanderBox->setPos(expanderX, y);
        }
        if (cnt > m_lineItem2Index) {
            TextItem *item = attribOpGroup->textItemAt(m_lineItem2Index);
            qreal y = item->mapToParent(item->boundingRect().bottomLeft()).y();
            m_classifierLines[1].setLine(m_classifierRect.left(), y, m_classifierRect.right(), y);
            qreal expanderX = rect().left() -
                m_operationExpanderBox->rect().width() - expanderDistance;
            m_operationExpanderBox->setPos(expanderX, y);
        }
        if (InvalidIndex == m_lineItem2Index) {  // attributes and operations invisible
            QPointF pos = m_attributeExpanderBox->pos();
            m_operationExpanderBox->setPos(pos.x(), pos.y() + 12);
        }
    }
}