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 » CExtGridCellObjectSize removing trailing zeros from the non fractional part of the number Collapse All
Subject Author Date
Malcolm D Oct 3, 2007 - 10:40 PM

(in 2.7 - you may have fixed it in 2.8 I haven’t checked yet)
When I use CExtGridCellObjectSize in a data grid, without changing any settings, it removes ’0’ (zeros) when it shouldn’t.
For example if the size should be 90 KB it displays this as 9 KB. (the original number is 92160, with units set to "KB")

It does this when m_bAllowTrailingZeroes is set to true (the default is "true" in CExtGridCellNumberBase). This variable should be set to true but it seems that the call to OnQueryTrailingZeroes() is used incorrectly in "CExtGridCellObjectSize::TextGet" - it trims any zeros, not just ones after the decimal separator.
The implementation of TextGet in CExtGridCellNumberBase seems to have the correct behaviour in regards to the usage of OnQueryTrailingZeroes().

Technical Support Oct 4, 2007 - 8:36 AM

Thank you for reporting the bug. Here is the fixed CExtGridCellObjectSize::TextGet() method

void CExtGridCellObjectSize::TextGet( CExtSafeString & strCopy ) const
{
	ASSERT_VALID( this );
	if(		(GetStyleEx()&__EGCS_EX_UNDEFINED_ROLE) != 0 
		||	IsEmpty()
		)
	{
		strCopy = _T("");
		return;

	}
	strCopy.Empty();

	if( this->vt == VT_EMPTY )
		return;

VARIANT varCopy;
	::VariantInit( &varCopy );
HRESULT hr = 
		stat_VariantCopy( 
			&varCopy, 
			LPVARIANT( LPCVARIANT( this ) )
			);
	if( FAILED(hr) )
	{
		ASSERT( FALSE );
		return;
	}

e_Mode_t eMode = GetMode();
INT nPower = 0;
	switch( eMode )

	{
	case eAuto:
		break;
	case eBytes:
		nPower = 1;
		break;
	case eKilobytes:
		nPower = 10;
		break;
	case eMegabytes:
		nPower = 20;
		break;
	case eGigabytes:
		nPower = 30;
		break;
	case eTerabytes:
		nPower = 40;

		break;
	case ePetabytes:
		nPower = 50;
		break;
	case eExabytes:
		nPower = 60;
		break;
	}

	VARIANT varRight;
	VARIANT varResult;
	::VariantInit( &varRight );
	::VariantInit( &varResult );
	if( nPower > 1 )

	{
		varRight.vt = VT_R8;
		V_R8(&varRight) = pow( 2.0, DOUBLE(nPower) );
		HRESULT hr = 
			::VarDiv(
				&varCopy,
				&varRight,
				&varResult
				);
		if( SUCCEEDED(hr) )
			stat_VariantCopy( 
				&varCopy, 
				&varResult 
				);
	}
	else if( nPower == 0 )

	{
		VARIANT varBase;
		::VariantInit( &varBase );
		varBase.vt = VT_R8;
		V_R8(&varBase) = 1024;

		INT nModeCurrent = INT( eKilobytes ); 
		for( nPower = 10; nPower <= 60; nPower += 10, nModeCurrent++ )
		{
			varRight.vt = VT_R8;
			V_R8(&varRight) = pow( 2.0, DOUBLE(nPower) );
			HRESULT hr = 
				::VarDiv(
					&varCopy,

					&varRight,
					&varResult
					);
			if( SUCCEEDED(hr) )
			{
				if(	stat_VariantCompare( &varResult, &varBase ) < 0 )
				{
					stat_VariantCopy( 
						&varCopy, 
						&varResult 
						);
					eMode = e_Mode_t( nModeCurrent );

					break;
				}
			}
		}
	}
	stat_VariantClear( &varRight );
	stat_VariantClear( &varResult );

CExtSafeString sNumberText;
	if( ! OnQueryNumberText( &varCopy, sNumberText ) )
		return;

UINT nNumDigits = OnQueryNumDigits( &varCopy );
	if( ! OnQueryTrailingZeroes() )
	{
		INT nPosPoint = sNumberText.ReverseFind( _T(’.’) );
		UINT nNumDigitsReal = 0;

		if( nPosPoint >= 0 )
			nNumDigitsReal = min( sNumberText.GetLength() - 1 - nPosPoint, 9 );
		if( nNumDigitsReal < nNumDigits )
			nNumDigits = nNumDigitsReal;
	}

	stat_VariantClear( &varCopy );

NUMBERFMT fmt;
	memset( &fmt, 0, sizeof(NUMBERFMT) );

	fmt.NumDigits = nNumDigits;
	fmt.LeadingZero = OnQueryLeadingZero();
	fmt.NegativeOrder = OnQueryNegativeOrder();

CExtSafeString sGrouping;
	OnQueryGrouping( sGrouping );
	sGrouping.Remove( _T(’;’) );

	sGrouping.TrimRight( _T(’0’) );
	fmt.Grouping = _ttoi( sGrouping );
	
CExtSafeString sDecimalSep;
	OnQueryDecimalSeparator( sDecimalSep );
	fmt.lpDecimalSep = sDecimalSep.GetBuffer( sDecimalSep.GetLength() );
	sDecimalSep.ReleaseBuffer();
	
CExtSafeString sThousandSep;
	OnQueryThousandSeparator( sThousandSep );
	fmt.lpThousandSep = sThousandSep.GetBuffer( sThousandSep.GetLength() );
	sThousandSep.ReleaseBuffer();

CExtSafeString sText;
	VERIFY(
		g_ResourceManager->GetNumberFormat(
			  0,

			  sNumberText,
			  &fmt,
			  sText.GetBuffer( 100 ),
			  100
			) != 0
		);
	sText.ReleaseBuffer();

CExtSafeString sAbbreviation;
	OnQuerySizeAbbreviation( eMode, sAbbreviation );
					
	strCopy.Format( _T("%s %s"), sText, sAbbreviation );
	strCopy.TrimRight();
}