Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » CExtLabel does not wrap long texts any more ? (Prof-UIS 2.81) Collapse All
Subject Author Date
Christophe Guibert Oct 29, 2007 - 11:53 AM

Dear Support Team,

When using long strings of text in CExtLabel controls, the text is not wrapped any more as it used to be with previous Prof-UIS versions.

Assuming there’s enough vertical space for multine label in the control, the text should be wrapped without adding \n characters in it, shouldn’t it ?

Is this on purpose ? How to revert to previous behavior ?

Best Regards,

Christophe guibert

Technical Support Nov 1, 2007 - 12:53 PM

Yes, you are right. This is a bug. Thank you. Please update the following method:

void CExtLabel::DoPaint( 
	CDC * pDC,
	CRect & rcClient
	)
{
	ASSERT_VALID( this );
	ASSERT_VALID( pDC );
CExtMemoryDC dc(
		pDC,
		&rcClient
		);
CRgn rgnClient;
	if( rgnClient.CreateRectRgnIndirect( &rcClient ) )
		dc.SelectClipRgn( &rgnClient );

	OnEraseBackground( dc, rcClient );

DWORD dwWndStyle = GetStyle();
DWORD dwWndType = (dwWndStyle&SS_TYPEMASK);
bool bCenterImage = ( (dwWndStyle&SS_CENTERIMAGE) != 0 );
	if( ! m_bmp.IsEmpty() )
	{
		bool bSmootherAsPossible = true;
		if( m_eImageMode == eStretch )
		{
			m_bmp.AlphaBlendSkinParts( 
				dc.GetSafeHdc(),
				rcClient,
				CRect(0,0,0,0), 
				CExtBitmap::__EDM_STRETCH,
				true,
				bSmootherAsPossible
				);
		}
		else if( m_eImageMode == eTile )
		{
			m_bmp.AlphaBlendSkinParts( 
				dc.GetSafeHdc(),
				rcClient,
				CRect(0,0,0,0), 
				CExtBitmap::__EDM_TILE,
				true,
				bSmootherAsPossible
				);
		}
		else if( m_eImageMode == eAlign )
		{
			CSize szSize = m_bmp.GetSize();
			CRect rcDst( 
				rcClient.left, 
				rcClient.top, 
				rcClient.left + szSize.cx, 
				rcClient.top + szSize.cy
				);

			switch( dwWndType )
			{
			case SS_RIGHT:
				rcDst.OffsetRect( rcClient.right - rcDst.right, 0 );
				break; 
			case SS_CENTER:
				rcDst.OffsetRect( ( (rcClient.right - rcClient.left) - (rcDst.right - rcDst.left) ) / 2, 0 );
				break;
			default: 
				// all the other types assumed as left
				break;
			}

			CRect rcSrc( 0, 0, szSize.cx, szSize.cy );
			rcDst.top = max( rcDst.top, rcClient.top );
			rcDst.left = max( rcDst.left, rcClient.left );
			rcDst.bottom = min( rcDst.bottom, rcClient.bottom );
			rcDst.right = min( rcDst.right, rcClient.right );

			if( ::RectVisible( dc.GetSafeHdc(), &rcDst ) )
			{
				INT nOldStretchBltMode =
					bSmootherAsPossible
						? ( ::GetStretchBltMode( dc.m_hDC ) )
						: ( COLORONCOLOR )
						;
				if( bSmootherAsPossible )
					::SetStretchBltMode(
						dc.m_hDC,
						( g_PaintManager.m_bIsWinNT )
							? HALFTONE
							: COLORONCOLOR
						);
				m_bmp.AlphaBlend(
					dc.m_hDC,
					rcDst,
					rcSrc
					);
				if( bSmootherAsPossible )
					::SetStretchBltMode(
						dc.m_hDC,
						nOldStretchBltMode
						);
			}
		}
	}
	else if( dwWndType == SS_ICON )
	{
		HICON hIcon = GetIcon();
		if( hIcon != NULL )
		{
			CExtCmdIcon _icon;
			_icon.AssignFromHICON( hIcon, true );
			CSize szIcon = _icon.GetSize();
			int nOffsetX = bCenterImage ? (rcClient.Width() - szIcon.cx) / 2 : 0;
			int nOffsetY = bCenterImage ? (rcClient.Height() - szIcon.cy) / 2 : 0;
			_icon.Paint(
				PmBridge_GetPM(),
				dc.GetSafeHdc(),
 				rcClient.left + nOffsetX,
 				rcClient.top + nOffsetY,
				-1,
				-1
				);
		}	
	}
	else
	{
		CExtSafeString strText;
		int nTextLen = GetWindowTextLength();
		if( nTextLen > 0 )
		{
			GetWindowText( strText.GetBuffer( nTextLen + 2 ), nTextLen + 1 );
			strText.ReleaseBuffer();
		}

		if( strText.GetLength() > 0 )
		{
			DWORD dwDrawTextFlags = 0;
			switch( dwWndType )
			{
			case SS_RIGHT:
				dwDrawTextFlags = DT_RIGHT; 
				break; 
			case SS_CENTER:
				dwDrawTextFlags = DT_CENTER;
				break;
			case SS_LEFTNOWORDWRAP:
				dwDrawTextFlags = DT_LEFT; 
				break;
			default: 
				// all the other types assumed as left
				dwDrawTextFlags = DT_LEFT; 
				break;
			} // switch( dwWndType )

			// do tabs expanding
			if( strText.Find( _T(’\t’) ) != -1 ) 
				dwDrawTextFlags |= DT_EXPANDTABS;

			if(		(dwWndType == SS_SIMPLE)
				||	(dwWndStyle&SS_CENTERIMAGE) != 0
				||	(dwWndStyle&SS_ENDELLIPSIS) != 0
				||	(dwWndStyle&SS_PATHELLIPSIS) != 0
				)
			{
				dwDrawTextFlags |= DT_SINGLELINE;

				if( (dwWndStyle&SS_CENTERIMAGE) != 0 )
					dwDrawTextFlags |= DT_VCENTER;
				if( (dwWndStyle&SS_ENDELLIPSIS) != 0 )
					dwDrawTextFlags |= DT_END_ELLIPSIS;
				if( (dwWndStyle&SS_PATHELLIPSIS) != 0 )
					dwDrawTextFlags |= DT_PATH_ELLIPSIS;
			}
			else
			{
				dwDrawTextFlags |= DT_WORDBREAK;
			}

			if( dwWndType == SS_LEFTNOWORDWRAP )
				dwDrawTextFlags &= ~(DT_WORDBREAK|DT_SINGLELINE);

			if( (dwWndStyle&SS_NOPREFIX) != 0 )
				dwDrawTextFlags |= DT_NOPREFIX;

			bool bEnabled = IsWindowEnabled() ? true : false;
			OnDrawLabelText(
				dc,
				rcClient,
				strText,
				dwDrawTextFlags,
				bEnabled
				);
		} // if( strText.GetLength() > 0 )
	}
	PmBridge_GetPM()->OnPaintSessionComplete( this );
	if( rgnClient.GetSafeHandle() != NULL )
		dc.SelectClipRgn( &rgnClient );	
}


Christophe Guibert Nov 8, 2007 - 2:37 PM

Hello,

Sorry for this late answer, I did not have the opportunity to integrate your fix earlier : thank you, it fixes all the CExtLabel that were encountered in the 2.81 Prof-UIS version.

Best Regards,

Christophe Guibert

Suhai Gyorgy Oct 29, 2007 - 12:42 PM

This has been discussed in a thread not so long ago. The solution:
Change CExtLabel.cpp @ line 238:

It is now:
bool bForceSingleLine =
( strText.Find( _T("\n") ) >= 0 ) ? true : false;

It should be:
bool bForceSingleLine =
( strText.Find( _T("\n") ) >= 0 ) ? false : true;

Christophe Guibert Oct 29, 2007 - 2:03 PM

I thank you for this answer, but it solves another problem, where \n characters were not properly managed.

In this case, it is slightly different : there are no \n characters in the string and the text should be wrapped when there’s enough room in the control height :

Behavior for long strings with Prof-UIS 2.80 CExtLabel for long strings (WITHOUT any \n chars)

-------------------------------------------
|a string of text that is much longer than|
|the control width, but can be wrapped    |
|when there’s enough height.              |
-------------------------------------------

New behavior for Prof-UIS 2.81 CExtLabel

-------------------------------------------
|a string of text that is much longer than|
|                                         |
|                                         |
-------------------------------------------


Best Regards,

Christophe Guibert

Christophe Guibert Oct 29, 2007 - 3:11 PM

In fact I think that the correction (in CExtLabel::DoPaint())

			bool bForceSingleLine = 
				( strText.Find( _T("\n") ) >= 0 ) ? false : true;

is wrong and it prevents any wrapping of text. It’s not because there are no \n in the string that the text should not be wrapped.
Further we find :
			if(		bForceSingleLine 
				||	dwWndType == SS_LEFTNOWORDWRAP
				||	(dwWndStyle&SS_ENDELLIPSIS) != 0
				||	(dwWndStyle&SS_PATHELLIPSIS) != 0
				)
			{
				dwDrawTextFlags |= DT_SINGLELINE;

				if( (dwWndStyle&SS_ENDELLIPSIS) != 0 )
					dwDrawTextFlags |= DT_END_ELLIPSIS;
				if( (dwWndStyle&SS_PATHELLIPSIS) != 0 )
					dwDrawTextFlags |= DT_PATH_ELLIPSIS;
			}
			else
			{
				dwDrawTextFlags |= DT_WORDBREAK;
			}



So there’s no chance to use the default DT_WORDBREAK when there’s no \n in the string !
The logics with the bForceSingleLine (when true) seems to be abusive.

Best Regards,

Christophe Guibert

Christophe Guibert Oct 29, 2007 - 3:02 PM

in fact I think that the correction
<code><pre>
bool bForceSingleLine =
                ( strText.Find( _T("\n") ) >= 0 ) ? false : true;