예제 #1
0
파일: Propbar.cpp 프로젝트: aolko/construct
void CExtGridCellNumberEx::TextGet( CExtSafeString & strCopy ) const
{
	ASSERT_VALID( this );
	if(		(GetStyleEx()&__EGCS_EX_UNDEFINED_ROLE) != 0 
		||	IsEmpty()
		)
	{
		strCopy = _T("");
		return;
	}
	strCopy.Empty();

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

CExtSafeString sNumberText;
bool bRet = OnQueryNumberText( &varCopy, sNumberText );
	
	::VariantClear( &varCopy );
	
	if( !bRet )
		return;

	UINT nNumDigits = OnQueryNumDigits();
//    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;
    }


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();

	VERIFY(
		g_ResourceManager->GetNumberFormat(
			  0,
			  sNumberText,
			  &fmt,
			  strCopy.GetBuffer( 100 ),
			  100
			) != 0
		);
	strCopy.ReleaseBuffer();
}
예제 #2
0
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;
		e_ImageMode_t eImageMode = GetImageMode();
		if( eImageMode == eStretch )
			m_bmp.AlphaBlendSkinParts( dc.GetSafeHdc(), rcClient, CRect(0,0,0,0), CExtBitmap::__EDM_STRETCH, true, bSmootherAsPossible );
		else if( eImageMode == eTouchInside || eImageMode == eTouchOutside )
		{
			CRect rcTouchSurface = rcClient;
			CExtMemoryDC dcTouch( &dc, rcTouchSurface, CExtMemoryDC::MDCOPT_TO_MEMORY|CExtMemoryDC::MDCOPT_FILL_BITS|CExtMemoryDC::MDCOPT_RTL_COMPATIBILITY );
			if( dcTouch.GetSafeHdc() )
			{
				CSize sizeTouchSrc = rcTouchSurface.Size();
				CSize sizeBmp = m_bmp.GetSize();
				double lfAspectX = double(rcTouchSurface.Width())  / double(sizeBmp.cx);
				double lfAspectY = double(rcTouchSurface.Height()) / double(sizeBmp.cy);
				double lfAspect = ( eImageMode == eTouchInside ) ? ( min( lfAspectX, lfAspectY ) ) : ( max( lfAspectX, lfAspectY ) );
				CSize sizeNew( LONG(double(sizeBmp.cx)*lfAspect), LONG(double(sizeBmp.cy)*lfAspect) );
				CRect rcTouchDst( rcTouchSurface.left, rcTouchSurface.top, rcTouchSurface.left + sizeNew.cx, rcTouchSurface.top + sizeNew.cy );
				if( eImageMode == eTouchInside )
				{				
					if( sizeNew.cx > sizeTouchSrc.cx )
						rcTouchDst.OffsetRect( ( sizeNew.cx - sizeTouchSrc.cx ) / 2, 0 );
					if( sizeNew.cy > sizeTouchSrc.cy )
						rcTouchDst.OffsetRect( 0, ( sizeNew.cy - sizeTouchSrc.cy ) / 2 );
				}
				else
				{
					rcTouchDst.OffsetRect( - ( sizeNew.cx - sizeTouchSrc.cx ) / 2, 0 );
					rcTouchDst.OffsetRect( 0, - ( sizeNew.cy - sizeTouchSrc.cy ) / 2 );
				}
				INT nOldStretchBltMode = bSmootherAsPossible ? ( ::GetStretchBltMode( dcTouch.m_hDC ) ) : ( COLORONCOLOR ) ;
				if( bSmootherAsPossible )
					::SetStretchBltMode( dcTouch.m_hDC, ( g_PaintManager.m_bIsWinNT ) ? HALFTONE : COLORONCOLOR );
				m_bmp.AlphaBlend( dcTouch.m_hDC, rcTouchDst );
				if( bSmootherAsPossible )
					::SetStretchBltMode( dcTouch.m_hDC, nOldStretchBltMode );
			}
		}
		else if( eImageMode == eTile )
			m_bmp.AlphaBlendSkinParts(  dc.GetSafeHdc(), rcClient, CRect(0,0,0,0), CExtBitmap::__EDM_TILE, true, bSmootherAsPossible );
		else if( eImageMode == eAlign )
		{
			CSize szSize = m_bmp.GetSize();
			CRect rcDst( rcClient.left, rcClient.top, rcClient.left + szSize.cx, rcClient.top + szSize.cy );
			bool bCenterHorizontally = false;
			switch( dwWndType )
			{
			case SS_RIGHT:  rcDst.OffsetRect( rcClient.right - rcDst.right, 0 ); break;
			case SS_CENTER: bCenterHorizontally = true;        break;
			default: /* all the other types assumed as left */ break;
			}
			if( bCenterHorizontally )
				rcDst.OffsetRect( ( (rcClient.right - rcClient.left) - (rcDst.right - rcDst.left) ) / 2, 0 );
			if( bCenterImage )
				rcDst.OffsetRect( 0, ( (rcClient.bottom - rcClient.top) - (rcDst.bottom - rcDst.top) ) / 2 );
			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,
				IsWindowEnabled() ? CExtCmdIcon::__PAINT_NORMAL : CExtCmdIcon::__PAINT_DISABLED
				);
		}
	}
	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 )
			if( strText.Find( _T('\t') ) != -1 ) // do tabs expanding
				dwDrawTextFlags |= DT_EXPANDTABS;
			if(		(dwWndType == SS_SIMPLE)
				||	(dwWndStyle&(SS_CENTERIMAGE|SS_ENDELLIPSIS|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 );	
}