Print Page | Close Window

[SOLVED]Backstage 2016 Style Left Aligned Controls

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=24080
Printed Date: 21 November 2024 at 10:34am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: [SOLVED]Backstage 2016 Style Left Aligned Controls
Posted By: cpede
Subject: [SOLVED]Backstage 2016 Style Left Aligned Controls
Date Posted: 16 October 2020 at 2:08am
There is a bug when using the full page xtpRibbonBackstageOffice2016Style style.

When adding controls  directly to the Ribbon, like the Minimize and Maximize Ribbon buttons, they are typically right aligned using e.g. pControlMinimize->SetFlags(xtpFlagRightAlign);
But if you omit this, and want the control to be left aligned, it is not hidden when opening the backstage in full mode.

It can easily be seen in the Ribbon sample, by removing the following line:

CXTPControl* pControlMinimize = pControls->Add(xtpControlButton, ID_RIBBON_MINIMIZE);
if (pControlMinimize)
{
      //pControlMinimize->SetFlags(xtpFlagRightAlign);
}




-------------
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)



Replies:
Posted By: cpede
Date Posted: 01 December 2020 at 5:08am
Any solution for this one?
Easy to reproduce in your samples.


-------------
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)


Posted By: dbrookes
Date Posted: 01 December 2020 at 9:26pm
As far as I can tell controls on the left side of ribbon tabs don't get given the xtpFlagRibbonTabBackground flag that controls on the right side of the ribbon tabs get. That flag does note that its for controls on the right side of the ribbon tabs. From CXTPRibbonBar Reposition:

    // Find control placed on Tab conttrol of ribbon but they are not tabs
    for (i = (int)arrFreeControls.GetSize() - 1; i >= 0; i--)
    {
        CXTPControl* pControl = arrFreeControls.GetAt(i);
        CRect rcControl          = pControl->GetRect();
        DWORD flags              = pControl->GetFlags();
        if ((rcControl.top >= m_rcTabControl.top) && (rcControl.bottom <= m_rcTabControl.bottom)
            && (rcControl.left >= m_rcTabControl.right))
            flags |= xtpFlagRibbonTabBackground;
        else
            flags &= ~xtpFlagRibbonTabBackground;
        pControl->SetFlags(flags);
    }

Therefore in CXTPRibbonBackstageView Popup these left side controls that don't have that flag are not hidden and added to m_listControlsToBeVisible to be made visible again later.

You might be able to override something in CXTPRibbonBar or CXTPRibbonBackstageView to work around this.

Regards,
Daniel.


Posted By: dbrookes
Date Posted: 01 December 2020 at 9:37pm
Actually thinking about it it may be possible to do something like this in the idle update handler for the command.

void CMainFrame::OnUpdate(CCmdUI *pCmdUI)
  {
  auto *pCommandBar = static_cast<CXTPCommandBar*>(pCmdUI->m_pOther);
  CXTPControl *pControl = CXTPControl::FromUI(pCmdUI);
  if (pControl)
    {
    // Is the control on the left hand side of the ribbon tabs.
    BOOL bOnRibbonBackgroundLHS = (pCommandBar->GetType() == xtpBarTypeRibbon && // Is the parent the ribbon bar?
                                   pControl->GetRibbonGroup() == NULL && // The control is not in a ribbon group!
                                   (pControl->GetFlags() & (xtpFlagRightAlign | xtpFlagRibbonTabBackground) == 0)); // The control is not right aligned!
    // If on the left hand side of the ribbon tabs, only show if backstage view is not visible.
    pControl->SetVisible(!bOnRibbonBackgroundLHS ||
                         !static_cast<CXTPRibbonBar*>(pCommandBar)->IsBackstageViewVisible());
    }

  pCmdUI->Enable(TRUE);
  }



Posted By: cpede
Date Posted: 02 December 2020 at 3:16am
Thanks for enlighten me, and pointing to the code causing the problem.

// Find control placed on Tab conttrol of ribbon but they are not tabs
for (i = (int)arrFreeControls.GetSize() - 1; i >= 0; i--)
{
    CXTPControl* pControl = arrFreeControls.GetAt(i);
    CRect rcControl   = pControl->GetRect();
    DWORD flags   = pControl->GetFlags();
    if ((rcControl.top >= m_rcTabControl.top) && (rcControl.bottom <= m_rcTabControl.bottom)
              && (rcControl.left >= m_rcTabControl.right))
        flags |= xtpFlagRibbonTabBackground;
    else
        flags &= ~xtpFlagRibbonTabBackground;
    pControl->SetFlags(flags);

I really don't understand the code in bold. It seems that the are using the flag dynamically?

I understand that if the user don't specify the xtpFlagRibbonTabBackground flag for right-aligned controls, they don't experience the Office way of showing the backstage, hiding the right-aligned control. So this is a kind of automatic feature, hiding all right-aligned controls in the ribbon to make it compatible.
But if the user manually add the xtpFlagRibbonTabBackground flag, why is it necessary to remove it, and showing left-aligned controls? When do you want to show a left-aligned control when the backstage is active?

I think this code can be removed, solving my problem. Alternatively overwriting the virtual CalcDockingLayout method, calling the default implementation and re-assign the xtpFlagRibbonTabBackground  flag to the left-aligned controls.



-------------
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)


Posted By: dbrookes
Date Posted: 02 December 2020 at 10:06pm
I think your right that xtpFlagRibbonTabBackground is a dynamic flag. Adding it yourself to the control doesn't really do anything useful as it will just be kept or removed the next time the ribbon recalculates its layout.

I think this bug of it not hiding on left side controls when the backstage is visible is just an oversight. The old Office themes still showed the tab background part of the ribbon bar when the backstage was opened, so this case probably just got missed.

An alternative, if you're going to patch it, you could adjust the rcControl and m_rcTabControl check to also check if the control is left of the tab control.
... && (rcControl.left >= m_rcTabControl.right || rcControl.right <= m_rcTabControl.left) ...



Posted By: cpede
Date Posted: 03 December 2020 at 2:00am
I removed the highlighted lines and everything works perfectly. I think you are right; most of this code, checking for non-right-aligned controls, can be skipped entirely for full page backstage modes aka. Office 2013/2016.
So, if anyone from CodeJock is listening in, please make the correction.


-------------
Product: Xtreme ToolkitPro (24.0.0)
Platform: Windows 10 (x64)
Language: Visual Studio 2017 (C++)


Posted By: agontarenko
Date Posted: 24 December 2020 at 4:50am
Hello,

It looks like this solution is correct.
I'm glad to inform you that the issue has been addressed and fixed. The fix will be available in the next beta or final release.

Regards,
Artem Gontarenko



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