Query about using SWF_MULTILINESHORTEN | developer.brewmp.com Query about using SWF_MULTILINESHORTEN | developer.brewmp.com

Developer

Query about using SWF_MULTILINESHORTEN

Forums:

I have some existing code which displays two lines of text within a static widget and would like to alter its behaviour slightly, but am unable to get the desired results.

The text contains two lines whose content is like this:

"[b] The first line[/b]/n The second line".

 

It is displayed in a static widget which is formatted like this:

IWidget_SetFlags(pStaticWgt, TWF_MULTILINE);

IWidget_SetFlags(pStaticWgt, SWF_WRAPTEXT | SWF_NOSHORTENTEXT);

 

This will result in a diplay like this:

The first line

The second line

 

However, sometimes the second line may be longer than the widget's extent in which case it will be displayed truncated like this:

The first line

The longer second l

 

I would like to change it so that elipses are displayed to indicate the second line is longer than the extent, i.e. I would like it to display like:

The first line

The longer second ...

 

I have tried removing SWF_NOSHORTENTEXT and using SWF_MULTILINESHORTEN and several combinations of flags but cannot get the desired results.

 

1) If I just use TWF_MULTILINE then the second line isn't displayed on a separate line

2) If I just use SWF_WRAPTEXT then the second line is displayed on a separate line but elipses are not displayed when its long

3) If I use SWF_WRAPTEXT | SWF_MULTILINESHORTEN then the second line isn't displayed at all.

4) If I use TWF_MULTILINE | SWF_WRAPTEXT | SWF_MULTILINESHORTEN then the second line isn't displayed at all.

5) If just use SWF_MULTILINESHORTEN then the second line isn't displayed at all.

 

What flags should I set to get the desired result I am seeking?

 

P.S.

What is the difference between TWF_MULTILINE and SWF_WRAPTEXT?

TWF_MULTILINE is a text widget flag. It is used to have multi-line text widget i.e. text entr is wrapped horizontally.
SWF_WRAPTEXT, static widget flag is used to wrap text horizontally to fit in widget rect. Text will be truncated vertically.
SWF_NOSHORTENTEXT, this static widget flag don't shorten text (no ellipsis) that doesn't fit in widget rect.
SWF_MULTILINESHORTEN, static widget flag wraps and truncates the text with an ellipsis in a multiline. This flag overrides SWF_WRAPTEXT. So using SWF_WRAPTEXT | SWF_MULTILINESHORTEN is of no use.
I was able to shorten the text in multiline by simply using SWF_MULTILINESHORTEN flag.

TWF_MULTILINE is a text widget flag. It is used to have multi-line text widget i.e. text entr is wrapped horizontally.
SWF_WRAPTEXT, static widget flag is used to wrap text horizontally to fit in widget rect. Text will be truncated vertically.
SWF_NOSHORTENTEXT, this static widget flag don't shorten text (no ellipsis) that doesn't fit in widget rect.
SWF_MULTILINESHORTEN, static widget flag wraps and truncates the text with an ellipsis in a multiline. This flag overrides SWF_WRAPTEXT. So using SWF_WRAPTEXT | SWF_MULTILINESHORTEN is of no use.
I was able to shorten the text in multiline by simply using SWF_MULTILINESHORTEN flag.

If I just use SWF_MULTILINESHORTEN  on its own the second line disappears.
// The text is first added to a vestor model:
....
int nItems = GetItemsCount();
ImageStaticInfo *pisi = NULL;
IImage *pii = ISHELL_LoadImage(m_lcUserCtx.piShell, imageFile);
ASSERT(pii);
ModelEvent mEv = { EVT_MDL_LIST_CHANGE, NULL, 0};

mEv.evCode= (nItems == 0) ? EVT_MDL_LIST_RESET : EVT_MDL_LIST_CHANGE;
if(nIndex <= nItems) {
ImageStaticInfo_New(&pisi, pii, richText);
if(nIndex == 0)
IVectorModel_Add(m_lcUserCtx.piVectorModel, (void*)pisi);
else
IVectorModel_InsertAt(m_lcUserCtx.piVectorModel,nIndex, (void*)pisi);
IListContainerModel_Notify(m_lcUserCtx.piListContainerModel, &mEv);

RELEASE_BASE(pii);
...

// Then later the model is added to the static widget and SWF_MULTILINESHORTEN applied:
...
nErr = ISHELL_CreateInstance(pData->piShell, AEECLSID_TypedValueModel, (void**)&piTVM);
if(AEE_SUCCESS == nErr ) {
// Attach a TypedValueModel to this widget
IWidget_SetModel(piwListItem, ITypedValueModel_to_IModel(piTVM));
if(LIST_ITEMTYPE_TEXTANDIMAGE == nType)
ITypedValueModel_AdaptSet(piTVM, cbListItemAdaptSet, piwListItem);

// Set widget extent
IWidget_GetPreferredExtent(piwListItem, &weStatic);
weStatic.height = 50;
IWidget_SetExtent(piwListItem, &weStatic);

nErr = ISHELL_CreateInstance(pData->piShell, AEECLSID_StaticWidget, (void**)&pStaticWgt);
if(AEE_SUCCESS == nErr) {
// Create a text model interface
nErr = ISHELL_CreateInstance(pData->piShell, AEECLSID_TextModel,(void**)&pTextMdl);

// Get the rich text model version
nErr = ITextModel_QueryInterface(pTextMdl, AEEIID_IRichTextModel,(void**)&pRichTextMdl);

// Add the model to the static widget
if (AEE_SUCCESS == nErr) {
nErr = IWidget_SetModel(pStaticWgt, (IModel*)pRichTextMdl);

IWidget_SetLeftPadding(pStaticWgt, 6);
IWidget_SetLineGap(pStaticWgt, 8);

RichTextSetFontMaps(pData->piShell, pStaticWgt);
//wrap our text and allow multi-line
IWidget_SetFlags(pStaticWgt, SWF_MULTILINESHORTEN);
IWidget_SetImageStaticStaticWidget(piwListItem, pStaticWgt);
if (AEE_SUCCESS == nErr) {
*ppiwItem = piwListItem;
ADDREFIF(*ppiwItem);
}
}

If I just use SWF_MULTILINESHORTEN  on its own the second line disappears.
// The text is first added to a vestor model:
....
int nItems = GetItemsCount();
ImageStaticInfo *pisi = NULL;
IImage *pii = ISHELL_LoadImage(m_lcUserCtx.piShell, imageFile);
ASSERT(pii);
ModelEvent mEv = { EVT_MDL_LIST_CHANGE, NULL, 0};

mEv.evCode= (nItems == 0) ? EVT_MDL_LIST_RESET : EVT_MDL_LIST_CHANGE;
if(nIndex <= nItems) {
ImageStaticInfo_New(&pisi, pii, richText);
if(nIndex == 0)
IVectorModel_Add(m_lcUserCtx.piVectorModel, (void*)pisi);
else
IVectorModel_InsertAt(m_lcUserCtx.piVectorModel,nIndex, (void*)pisi);
IListContainerModel_Notify(m_lcUserCtx.piListContainerModel, &mEv);

RELEASE_BASE(pii);
...

// Then later the model is added to the static widget and SWF_MULTILINESHORTEN applied:
...
nErr = ISHELL_CreateInstance(pData->piShell, AEECLSID_TypedValueModel, (void**)&piTVM);
if(AEE_SUCCESS == nErr ) {
// Attach a TypedValueModel to this widget
IWidget_SetModel(piwListItem, ITypedValueModel_to_IModel(piTVM));
if(LIST_ITEMTYPE_TEXTANDIMAGE == nType)
ITypedValueModel_AdaptSet(piTVM, cbListItemAdaptSet, piwListItem);

// Set widget extent
IWidget_GetPreferredExtent(piwListItem, &weStatic);
weStatic.height = 50;
IWidget_SetExtent(piwListItem, &weStatic);

nErr = ISHELL_CreateInstance(pData->piShell, AEECLSID_StaticWidget, (void**)&pStaticWgt);
if(AEE_SUCCESS == nErr) {
// Create a text model interface
nErr = ISHELL_CreateInstance(pData->piShell, AEECLSID_TextModel,(void**)&pTextMdl);

// Get the rich text model version
nErr = ITextModel_QueryInterface(pTextMdl, AEEIID_IRichTextModel,(void**)&pRichTextMdl);

// Add the model to the static widget
if (AEE_SUCCESS == nErr) {
nErr = IWidget_SetModel(pStaticWgt, (IModel*)pRichTextMdl);

IWidget_SetLeftPadding(pStaticWgt, 6);
IWidget_SetLineGap(pStaticWgt, 8);

RichTextSetFontMaps(pData->piShell, pStaticWgt);
//wrap our text and allow multi-line
IWidget_SetFlags(pStaticWgt, SWF_MULTILINESHORTEN);
IWidget_SetImageStaticStaticWidget(piwListItem, pStaticWgt);
if (AEE_SUCCESS == nErr) {
*ppiwItem = piwListItem;
ADDREFIF(*ppiwItem);
}
}

I wasn't able to replicate the issue; tried with imagestatic widget, list widget with imagestatic as well. I could shorten the long text and display it in multiple lines. Sorry I couldn't understand your code snippet; can you please elaborate further?

I wasn't able to replicate the issue; tried with imagestatic widget, list widget with imagestatic as well. I could shorten the long text and display it in multiple lines. Sorry I couldn't understand your code snippet; can you please elaborate further?