Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - [SOLVED]Backstage 2016 Style Left Aligned Controls
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

[SOLVED]Backstage 2016 Style Left Aligned Controls

 Post Reply Post Reply
Author
Message
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 668
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post Topic: [SOLVED]Backstage 2016 Style Left Aligned Controls
    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++)
Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 668
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post 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++)
Back to Top
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post 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);
  }

Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 668
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post 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++)
Back to Top
dbrookes View Drop Down
Groupie
Groupie


Joined: 30 August 2019
Location: Australia
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote dbrookes Quote  Post ReplyReply Direct Link To This Post 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) ...

Back to Top
cpede View Drop Down
Senior Member
Senior Member


Joined: 13 August 2004
Location: Denmark
Status: Offline
Points: 668
Post Options Post Options   Thanks (0) Thanks(0)   Quote cpede Quote  Post ReplyReply Direct Link To This Post 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++)
Back to Top
agontarenko View Drop Down
Admin Group
Admin Group


Joined: 25 March 2016
Status: Offline
Points: 293
Post Options Post Options   Thanks (0) Thanks(0)   Quote agontarenko Quote  Post ReplyReply Direct Link To This Post 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
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.157 seconds.