Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Command Bars
  New Posts New Posts RSS Feed - How to set image ID for CXTPRecentFileListBox item
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

How to set image ID for CXTPRecentFileListBox item

 Post Reply Post Reply
Author
Message
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 886
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post Topic: How to set image ID for CXTPRecentFileListBox item
    Posted: 20 November 2014 at 6:53pm
We are using the CJ CXTPRibbonBackstagePageRecent class for our recent documents page in the backstage window.

I am adding files to the list and I get icons when the page displays. But that only works if we are showing the user a file name in the window. But we want to show the user a formula for managed documents instead of a fully qualified file name. I can get the images for our files loaded into the image manger being used. But there's one catch, unlike almost every other CJ control that has an image ID in its instance data, I can't find a way to set the image ID. The member is private so I don't have access to it.

I'd also like to swap out the tooltip context so I can use one of our own derived tooltip context objects we use elsewhere that provides a tooltip that shows a preview of the file but I can't figure out how to do that either. I can call a CXTPRecentFileListBox::GetTooltipContext method, but I can't find a SetTooltipContext method.

How can I set the image for the icon displayed with the file?

How can I set a custom CXTPTooltipContext derived object as the tooltip context for the items?
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 May 2017 at 3:58am
Hello rdhd,

I have added getter and setter for CXTPControlGalleryItem::m_nImage  in CXTPRecentFileListBoxItem and derived class  CXTPControlGalleryItem. This setter properly save custom image index in original  CXTPRecentFileListBoxItem::m_pRecentItem. This bug can be reproduced with setting custom icons and then pin/unpin item  -> custom icons will be updated with system icons. Fix will be available soon in beta or release version of 18.0.

About TooltipContext you can inherit class CXTPRecentFileListBox to manage TooltipContext.
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 May 2017 at 9:25am
Example for using custom icons in C++
(Samples\Ribbon\RibbonSample\MainFrm.h and MainFrm.cpp)
change type of CMainFrame::m_pageRecent to CXTPRibbonBackstagePageRecentCustom
then add  m_pageRecent.InitCustomIcons();   in  CMainFrame::CreateBackstage()

class CXTPRibbonBackstagePageRecentCustom : public CXTPRibbonBackstagePageRecent
{
public:
             CXTPRibbonBackstagePageRecentCustom();
    virtual ~CXTPRibbonBackstagePageRecentCustom();

public:
    virtual void InitCustomIcons();
    virtual BOOL OnSetActive();

protected:
    CXTPImageManager* m_pCustomIcons;
};


CXTPRibbonBackstagePageRecentCustom::CXTPRibbonBackstagePageRecentCustom()
: m_pCustomIcons(NULL)
{

}

CXTPRibbonBackstagePageRecentCustom::~CXTPRibbonBackstagePageRecentCustom()
{
    if (m_pCustomIcons)    
        m_pCustomIcons->InternalRelease();
}

void CXTPRibbonBackstagePageRecentCustom::InitCustomIcons()
{
    CBitmap bmp;
    XTPResourceManager()->LoadBitmap(&bmp, XTP_IDB_CUSTOMIZE_ICONS);        //    XTP_IDB_WORKSPACE_ICONS

    BITMAP bmpInfo;
    bmp.GetBitmap(&bmpInfo);
    UINT nCount = bmpInfo.bmWidth / 16;

    if (m_pCustomIcons)
        m_pCustomIcons->InternalRelease();

    m_pCustomIcons = new CXTPImageManager;

    UINT* pIDs = new UINT[nCount];
    for (UINT i = 0; i < nCount; i++)
    {
        pIDs[ i ] = i + 1;
    }
    VERIFY(m_pCustomIcons->SetIcons(bmp, pIDs, nCount, CSize(16, 16), xtpImageNormal));
    delete[] pIDs;
        
    UINT nIDs[] = {0, 1001, 1000};    //ID_ICON_UNPINNED, ID_ICON_PINNED
    m_pCustomIcons->SetIcons(XTP_IDB_RIBBON_PINICON, nIDs, 3, CSize(16, 16), xtpImageNormal);
    
    m_wndList.GetItems()->SetImageManager(m_pCustomIcons);
    m_pCustomIcons->InternalAddRef();
}

BOOL CXTPRibbonBackstagePageRecentCustom::OnSetActive()
{
    CXTPRecentFileList* pRecentFileList = (CXTPRecentFileList*) m_wndList.GetRecentFileList();
    if (pRecentFileList && pRecentFileList->m_strOriginal == _T("PinableRecentFileList"))
    {
        for (int nIndex = 0; nIndex < pRecentFileList->m_nSize; nIndex++)
        {
            CXTPRecentFileListItem* pItem = pRecentFileList->GetItem(nIndex);
            if (!pItem)
                continue;

            //if ( some_condition ) then set_some_icon
            pItem->SetIconId(nIndex+1);
        }

        m_wndList.BuildItems((CXTPRecentFileList*)pRecentFileList);

        return TRUE;
    }

    return FALSE;
}


Also example for VisualBasic, two variants of editing (used sample project Samples\CommandBars\VB\RibbonSample\pageBackstageRecent.frm):

Public Sub Activate()
  RecentFileListBox.Icons.LoadBitmap App.Path & "\res\office2013_backstage_32x32.bmp", Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), xtpImageNormal

'sample with editing items BEFORE calling CreateRecentFileListItems
  Dim RFLItem As RecentFileListItem
  For i = 1 To RecentFileList.Count
    Set RFLItem = RecentFileList.Item(i)
    If Not RFLItem Is Nothing Then
    
      If InStr(RFLItem.PathName, "bas") Then
        RFLItem.IconId = 1
      Else
        RFLItem.IconId = 2
      End If
    
    End If
  Next
  
  RecentFileListBox.CreateRecentFileListItems RecentFileList
End Sub

Public Sub Activate()
  RecentFileListBox.Icons.LoadBitmap App.Path & "\res\office2013_backstage_32x32.bmp", Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), xtpImageNormal
  RecentFileListBox.CreateRecentFileListItems RecentFileList

'sample with editing items AFTER calling CreateRecentFileListItems 
  Dim RFLItem As CommandBarGalleryItem
  For i = 0 To RecentFileListBox.Items.Count
  
    Set RFLItem = RecentFileListBox.Items.Item(i)
  
    If Not RFLItem Is Nothing Then
      If InStr(RFLItem.Caption, "bas") Then
          RFLItem.ImageIndex = 1
      Else
          RFLItem.ImageIndex = 2
      End If
    End If
  Next
End Sub

Please note that in first case used RecentFileList with item's type RecentFileListItem and in second case used RecentFileListBox with item's type CommandBarGalleryItem.
Those two item's types have different properties to get access to image and text:

RecentFileListItem.PathName
RecentFileListItem.IconId

CommandBarGalleryItem.Caption
CommandBarGalleryItem.ImageIndex

Also note that indexes of items in RecentFileList starts from 0 and for RecentFileListBox starts from 1.

 For i = 1 To RecentFileList.Count
 ...

 For i = 0 To RecentFileListBox.Items.Count
 ... 

Regards,
Oleksandr Lebed 

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.187 seconds.