Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - [solved] Ribbon xtpControlPopup SetWidth() problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

[solved] Ribbon xtpControlPopup SetWidth() problem

 Post Reply Post Reply
Author
Message
renninha View Drop Down
Groupie
Groupie


Joined: 10 August 2007
Location: Sweden
Status: Offline
Points: 17
Post Options Post Options   Thanks (1) Thanks(1)   Quote renninha Quote  Post ReplyReply Direct Link To This Post Topic: [solved] Ribbon xtpControlPopup SetWidth() problem
    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.
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
Marco1 View Drop Down
Senior Member
Senior Member


Joined: 16 January 2004
Location: Germany
Status: Offline
Points: 251
Post Options Post Options   Thanks (0) Thanks(0)   Quote Marco1 Quote  Post ReplyReply Direct Link To This Post Posted: 25 February 2018 at 12:39pm
Oleg, is it possible to release a 18.3.1 (for this) soon?
Would really appreciate that.

Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post Posted: 25 February 2018 at 1:12pm
Hello Marco

You confused me with 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
Back to Top
olebed View Drop Down
Admin Group
Admin Group


Joined: 01 July 2014
Location: Ukraine
Status: Offline
Points: 841
Post Options Post Options   Thanks (0) Thanks(0)   Quote olebed Quote  Post ReplyReply Direct Link To This Post 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);
        }

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.141 seconds.