Print Page | Close Window

[solved] Ribbon xtpControlPopup SetWidth() problem

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=23585
Printed Date: 19 April 2024 at 11:19pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: [solved] Ribbon xtpControlPopup SetWidth() problem
Posted By: renninha
Subject: [solved] Ribbon xtpControlPopup SetWidth() problem
Date Posted: 22 February 2018 at 9:24am
Hi,

Just upgraded to 18.3 from 18.2 and now the pButton->SetWidth() causes the button's caption to disappear, only the icon remains (xtpButtonIconAndCaption). Worked fine in 18.2 and earlier versions.



Is it a bug or show I now use a different parameter to do this?

Thanks.



Replies:
Posted By: olebed
Date Posted: 22 February 2018 at 2:33pm
Hello HÃ¥kan Renning,

Thanks a lot for bringing this to our attention.
I'm glad to inform you that the issue has been addressed and fixed.
Problem was due to recent changes for drawing icons with custom size on CommandBars.
CSize CXTPPaintManager::DrawControlToolBarParent(CDC* pDC, CXTPControl* pButton, BOOL bDraw)
{
.......
    if (bDrawImage)
    {
        if (!bVert)
            szIcon.cx += XTP_DPI_X(3) * 2;
        else
            szIcon.cy += XTP_DPI_Y(3) * 2;    
    }

    switch (controlType)
    {
    case xtpControlPopup:
        {
            if (!bDrawImage)
            {
                CSize sz = DrawControlText(pDC, pButton, rcButton, bDraw, bVert, TRUE, !bDraw || pButton->GetParent()->GetType() != xtpBarTypeMenuBar);

                if (pButton->GetID() == XTP_ID_CUSTOMIZE_ADDORREMOVE)
                {
                    sz = CSize(sz.cx + XTP_DPI_X(14), sz.cy + XTP_DPI_Y(10));
                }
                else
                {
                    sz = CSize(sz.cx + XTP_DPI_X(6), sz.cy + XTP_DPI_Y(6));
                }

                return GetControlSize(pButton, sz, bVert);
            }
            else
            {
                if (!bDrawText)
                {
                    CPoint pt = CPoint(rcButton.right - XTP_DPI_X(7) / 2, rcButton.CenterPoint().y);
                    DrawDropDownGlyph(pDC, pButton, pt, pButton->GetSelected(), pButton->GetPopuped(), pButton->GetEnabled(), FALSE);
                    return GetControlSize(pButton, CSize(szIcon.cx + XTP_DPI_X(7), szButton.cy), bVert);
                }
                return GetControlSize(pButton, DrawControlText(pDC, pButton, rcButton, bDraw, pButton->GetParent()->GetType() != xtpBarTypeMenuBar, szIcon, bDrawImage), bVert);
            }
        }
    case xtpControlSplitButtonPopup:
        {
            if (!bDrawImage)
                szButton = CSize(XTP_COMMANDBAR_MIN_CONTROL_HEIGHT, XTP_COMMANDBAR_MIN_CONTROL_HEIGHT);
            else
                szButton.cx = szIcon.cx;

            if (!bDrawText)
                return GetControlSize(pButton, CSize(szButton.cx + m_nSplitButtonDropDownWidth, szButton.cy), bVert);

            rcButton.right -= m_nSplitButtonDropDownWidth;

            CSize sz = DrawControlText(pDC, pButton, rcButton, bDraw, FALSE, szIcon, bDrawImage);
            return GetControlSize(pButton, CSize(sz.cx + m_nSplitButtonDropDownWidth, sz.cy), bVert);

        }
    case xtpControlButtonPopup:
    case xtpControlButton:
    case xtpControlLabel:
    case xtpControlCheckBox:
    case xtpControlGallery:
        {
            if (!bDrawText)
                return GetControlSize(pButton, szButton, bVert);

            if (!bDrawImage) szButton = CSize(XTP_COMMANDBAR_MIN_CONTROL_HEIGHT, szButton.cy);

            return GetControlSize(pButton, DrawControlText(pDC, pButton, rcButton, bDraw, FALSE, szIcon, bDrawImage), bVert);
        }
    }
    return 0;
}
Regards,
 Oleksandr Lebed


Posted By: olebed
Date Posted: 24 February 2018 at 6:47pm
Hello,

I've fixed also calculating and drawing triangles on popup and splitPopup  controls in cases with empty labels.  I've added this changes to previous code snippet.

Also I've fixed precalculation size of Edit and ComboBox controls of CommandBar/Ribbon
CSize CXTPPaintManager::DrawControlEdit(CDC* pDC, CXTPControlEdit* pControlEdit, BOOL bDraw)
{
......

    BOOL bImageVisible = pControlEdit->IsImageVisible();
    CSize szIcon = CSize(0);
    if (bImageVisible)
    {
        szIcon = pControlEdit->GetIconSize();
        CSize szAvailable = CSize(XTP_DPI_X(szIcon.cx) + XTP_DPI_X(2) * 2, nHeight);
        CXTPImageManagerIcon* pImage = pControlEdit->GetImage(szIcon.cx);
        szIcon = GetStretchIconSizeDPIAwareness(pImage, szIcon, pControlEdit, szAvailable);
    }

    int nLabelWidth = (bImageVisible ? szIcon.cx  + XTP_DPI_X(3) * 2 : 0) +
        (bCaptionVisible ? nCaptionWidth : 0);

    if (bImageVisible)
        nHeight = max(nHeight, pControlEdit->GetButtonSize().cy);

    pControlEdit->SetLabelWidth(nLabelWidth);

    return CSize(pControlEdit->GetWidth(), nHeight);
}

CSize CXTPPaintManager::DrawControlComboBox(CDC* pDC, CXTPControlComboBox* pControlCombo, BOOL bDraw)
{
......

    BOOL bImageVisible = pControlCombo->IsImageVisible();
    CSize szIcon = CSize(0);
    if (bImageVisible)
    {
        szIcon = pControlCombo->GetIconSize();
        CSize szAvailable = CSize(XTP_DPI_X(szIcon.cx) + XTP_DPI_X(2) * 2, nHeight);
        CXTPImageManagerIcon* pImage = pControlCombo->GetImage(szIcon.cx);
        szIcon = GetStretchIconSizeDPIAwareness(pImage, szIcon, pControlCombo, szAvailable);
    }

    int nLabelWidth = (bImageVisible ? szIcon.cx  + XTP_DPI_X(3) * 2 : 0) +
        (bCaptionVisible ? nCaptionWidth : 0);

    if (bImageVisible)
        nHeight = max(nHeight, pControlCombo->GetParent()->GetButtonSize().cy);

    pControlCombo->SetLabelWidth(nLabelWidth);

    return CSize(pControlCombo->GetWidth(), nHeight);
}

Also for using DPIScalingOption in ComboBox control we should set correct pointer to CommandBars on ComboBox creation (see implementation of CXTPPaintManager::IsDPIIconsScallingEnabled)
CXTPControl* CXTPControls::Add(XTPControlType controlType, int nId, LPCTSTR strParameter, int nBefore, BOOL bTemporary)
{
    CXTPControl* pControl = NULL;
    CXTPCommandBars* pCommandBars = GetCommandBars();

    switch (controlType)
    {
        case xtpControlCustom:
            return Add(new CXTPControlCustom(), nId, strParameter, nBefore, bTemporary);

        case xtpControlButton:
            if (nId == XTP_ID_WINDOWLIST) pControl = (CXTPControl*)CXTPControlWindowList::CreateObject();
            else if (nId == XTP_ID_WORKSPACE_ACTIONS) pControl = (CXTPControl*)CXTPControlWorkspaceActions::CreateObject();
            else if (nId == ID_VIEW_TOOLBAR) pControl = (CXTPControl*)CXTPControlToolbars::CreateObject();
            else if (nId == XTP_ID_FILE_MRU && !bTemporary) pControl = (CXTPControl*)CXTPControlRecentFileList::CreateObject();
            else
            pControl = (CXTPControl*)CXTPControlButton::CreateObject();
            break;

        case xtpControlComboBox:
            pControl = (CXTPControl*)CXTPControlComboBox::CreateObject();
            if (pControl->GetCommandBar())
                pControl->GetCommandBar()->SetCommandBars(pCommandBars);
            break;
........

Regards,
 Oleksandr Lebed


Posted By: Marco1
Date Posted: 25 February 2018 at 12:39pm
Oleg, is it possible to release a 18.3.1 (for this) soon?
Would really appreciate that.



-------------
Product: XTP 18.3.0 on VS 2017
Platform: VS 2017 / Windows 10 (64bit)


Posted By: olebed
Date Posted: 25 February 2018 at 1:12pm
Hello Marco

You confused me with http://forum.codejock.com/member_profile.asp?PF=6851" rel="nofollow - Oleg . As I know he doesn't work for Codejock from 2012 or 2013 year.

About next release - it is timeless question for which I don't have answer. So I post there small fixes. This also gives possibility to quick confirmation of solution before release.

However this isn't useful for ActiveX customers. But we can share recent OCXes with support website.

Regards,
 Oleksandr Lebed


Posted By: olebed
Date Posted: 29 March 2018 at 8:07am
Little addition to drawing CommandBar buttons with custom size and enabled property TextBelowIcons

CSize CXTPPaintManager::DrawControlToolBarParent(CDC* pDC, CXTPControl* pButton, BOOL bDraw)
{
.......

    if (pButton->GetParent()->IsTextBelowIcons() && bDrawImage)
    {
        CXTPFontDC fontHorizontal (pDC, pButton->IsItemDefault() ? &m_xtpFontRegularBold : &m_xtpFontRegular);
        BOOL bTriangled = controlType == xtpControlPopup;

        if (bDraw)
        {
            if (controlType == xtpControlSplitButtonPopup) rcButton.right -= m_nSplitButtonDropDownWidth;
    
            CPoint pt = CPoint(rcButton.CenterPoint().x - szIcon.cx / 2, rcButton.top + XTP_DPI_Y(4));

            DrawImage(pDC, pt, szIcon, pImage, bSelected, bPressed, bEnabled, bChecked, bPopuped);

            CRect rcText = rcButton;
            rcText.top += szIcon.cy + XTP_DPI_Y(4);

            DrawControlText(pDC, pButton, rcText, TRUE, FALSE, TRUE, bTriangled);
        }




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net