How does text work in the indexnavigator control?

PDF-XChange Editor SDK for Developers

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
RMan
User
Posts: 247
Joined: Tue Jul 02, 2013 10:06 pm

How does text work in the indexnavigator control?

Post by RMan »

m_spDestBeforeAfter->put_Count(2);
m_spDestBeforeAfter->SetStrings(CComBSTR(L"Before\nAfter"));
m_spDestBeforeAfter->UpdateItems(0, 2);
m_spDestBeforeAfter->put_SelIndex(m_insertDest.after ? 1UL : 0UL);

We get 2 buttons but they just give a number and not the actual text.
Destination.jpg
You do not have the required permissions to view the files attached to this post.
RMan
User
Posts: 247
Joined: Tue Jul 02, 2013 10:06 pm

Re: How does text work in the indexnavigator control?

Post by RMan »

Also is there any easy way to make it work with your built-in translations. I'm guessing these are the string ID's for inserting pages.
InsertPosCtl.Destination = 13527
InsertPosCtl.Location = 13528
InsertPosCtl.BeforeAfter = 13529
InsertPosCtl.Page = 13530
InsertPosCtl.Pages = 13531
InsertPosCtl.ExactEdit = 13532
InsertPosCtl.Total = 13533
User avatar
Sean - PDF-XChange
Site Admin
Posts: 1353
Joined: Wed Sep 14, 2016 5:42 pm

Re: How does text work in the indexnavigator control?

Post by Sean - PDF-XChange »

Hi RMan,

I've asked the development team for their input here.

Kind regards,
Sean Godley
Technical Writer
PDF-XChange Co LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623
User avatar
MishaH
User
Posts: 41
Joined: Wed Sep 11, 2024 1:43 pm

Re: How does text work in the indexnavigator control?

Post by MishaH »

Hi RMan,


1. Customizing the IndexNavigator item text
Implement your own `IUIX_IndexNavigatorCallbacks` and override `IndexNav_OnGetItemText` to provide the desired text for each item. For example, assuming m_sBefore and m_sAfter contain the corresponding localized strings:

Code: Select all

HRESULT MyIndexNavigatorCallbacks::IndexNav_OnGetItemText(IUIX_IndexNavigator* pIndexNav, LONG nIndex, LPWSTR* sText, LONG* nTextLen)
{
    if (!pIndexNav || !sText || !nTextLen)
        return E_INVALIDARG;

    if ((DWORD)nIndex > 1)
        return E_INVALIDARG;

    const auto& str = (nIndex == 0) ? m_sBefore : m_sAfter;
    *sText = str;
    *nTextLen = str.Length();

    return S_OK;
}
2. Retrieving the built-in localized strings
The identifiers you found refer to the controls used in our implementation, rather than to the actual strings displayed by those controls. The corresponding text strings have separate identifiers.

You can use `IPXV_Inst::GetLocalStr` to retrieve the built-in localized strings by their string identifiers. For example:

Code: Select all

CComBSTR m_sBefore, m_sAfter;
pVInst->GetLocalStr(L"PageInsert.Location.Before", &m_sBefore);
pVInst->GetLocalStr(L"PageInsert.Location.After", &m_sAfter);
You can retrieve these strings during initialization and then return the appropriate one from IndexNav_OnGetItemText based on the navigator item's index.

I hope this helps.

Kind regards,
Misha
RMan
User
Posts: 247
Joined: Tue Jul 02, 2013 10:06 pm

Re: How does text work in the indexnavigator control?

Post by RMan »

Thanks we have the text working. Now is there a flag I'm missing so the main indexnavigator contol resizes based on the content or so we have to calculate each itemtext width and calculate the total width?
User avatar
MishaH
User
Posts: 41
Joined: Wed Sep 11, 2024 1:43 pm

Re: How does text work in the indexnavigator control?

Post by MishaH »

Hi RMan,

The width of each IndexNavigator item is calculated automatically based on the text returned by `IndexNav_OnGetItemText`.
If you need to customize the item width calculation, you can override `IndexNav_OnGetItemTextWidth`. Here is an example of how the item width is currently calculated:

Code: Select all

HRESULT MyIndexNavigatorCallbacks::IndexNav_OnGetItemTextWidth(IUIX_IndexNavigator* pIndexNav, LONG nIndex, LPWSTR pText, LONG nTextLen, IUIX_Font* pFont, LONG* nTextWidth)
{
    if (!pIndexNav || !m_pObj || !nTextWidth)
        return E_INVALIDARG;

    SIZE sz = { 0 };
    LONG nDrawTextFlags = 0;
    m_pObj->CalcStringSize(pText, nTextLen, pFont, &sz, nDrawTextFlags);
    *nTextWidth = sz.cx;

    return S_OK;
}
To make the IndexNavigator control itself fit its content, use `IUIX_IndexNavigator::CalcContentWidth`. Run this code during control initialization and whenever the layout changes:

Code: Select all

CComPtr<IUIX_Obj> pObj;
pIndexNav->get_Obj(&pObj);
if (pObj)
{
    RECT rcIndexNav = { 0 };
    pObj->get_Rect(&rcIndexNav);

    LONG nAvailWidth = 1000; // Maximum available width within the parent Group control, based on the current layout.

    LONG nWidth = 0;
    pIndexNav->CalcContentWidth(nAvailWidth, &nWidth);

    rcIndexNav.right = rcIndexNav.left + nWidth;
    pObj->Move(&rcIndexNav, VARIANT_TRUE);
}
Please let me know if this works for you.

Kind regards,
Misha
RMan
User
Posts: 247
Joined: Tue Jul 02, 2013 10:06 pm

Re: How does text work in the indexnavigator control?

Post by RMan »

Misha thank you so much. We were close but a few pixels off and twice as much code the way we were trying it.

One last thing is how to make part of the text bold like we can in the labels. viewtopic.php?t=50522