ExtPaintManager.cpp
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:1653k
- dc.DrawText(
- sItemText,
- sItemText.GetLength(),
- rcText,
- nFormat
- );
- }
- dc.SelectObject( pOldFont );
- dc.SetBkMode( nOldBkMode );
- dc.SetTextColor( clrOldText );
- } // if we have sense to paint text on tab item
- if( pIconTabItemCloseButton != NULL )
- {
- ASSERT( ! pIconTabItemCloseButton->IsEmpty() );
- if( dc.RectVisible( &rcTabItemCloseButton ) )
- pIconTabItemCloseButton->Paint(
- g_PaintManager.GetPM(),
- dc.m_hDC,
- rcTabItemCloseButton,
- ePaintStateITICB
- );
- } // if( pIconTabItemCloseButton != NULL )
- }
- void CExtPaintManagerNativeXP::PaintTabItem(
- CDC & dc,
- CRect & rcTabItemsArea,
- bool bTopLeft,
- bool bHorz,
- bool bSelected,
- bool bCenteredText,
- bool bGroupedMode,
- bool bInGroupActive,
- bool bInvertedVerticalMode,
- const CRect & rcEntireItem,
- CSize sizeTextMeasured,
- CFont * pFont,
- __EXT_MFC_SAFE_LPCTSTR sText,
- CExtCmdIcon * pIcon,
- CObject * pHelperSrc,
- LPARAM lParam, // = 0L
- COLORREF clrForceText, // = COLORREF(-1L)
- COLORREF clrForceTabBk, // = COLORREF(-1L)
- COLORREF clrForceTabBorderLT, // = COLORREF(-1L)
- COLORREF clrForceTabBorderRB, // = COLORREF(-1L)
- COLORREF clrForceTabSeparator, // = COLORREF(-1L)
- bool bDwmMode // = false
- )
- {
- ASSERT_VALID( this );
- ASSERT( dc.GetSafeHdc() != NULL );
- if( bGroupedMode
- || (! g_PaintManager.m_UxTheme.IsControlsThemed() )
- )
- {
- CExtPaintManager::PaintTabItem(
- dc,
- rcTabItemsArea,
- bTopLeft,
- bHorz,
- bSelected,
- bCenteredText,
- bGroupedMode,
- bInGroupActive,
- bInvertedVerticalMode,
- rcEntireItem,
- sizeTextMeasured,
- pFont,
- sText,
- pIcon,
- pHelperSrc,
- lParam,
- clrForceText,
- clrForceTabBk,
- clrForceTabBorderLT,
- clrForceTabBorderRB,
- clrForceTabSeparator,
- bDwmMode
- );
- return;
- }
- LONG nItemIndex = 1;
- CExtCmdIcon * pIconTabItemCloseButton = NULL;
- CExtCmdIcon::e_paint_type_t ePaintStateITICB =
- (CExtCmdIcon::e_paint_type_t) CExtCmdIcon::__PAINT_INVISIBLE;
- CRect rcTabItemCloseButton( 0, 0, 0, 0 );
- CExtBarButton * pTBB = NULL;
- CExtTabWnd * pTabs = NULL;
- CExtTabWnd::TAB_ITEM_INFO * pTII = NULL;
- bool bNoPrefix = false;
- if( pHelperSrc != NULL )
- {
- pTabs = DYNAMIC_DOWNCAST( CExtTabWnd, pHelperSrc );
- if( pTabs != NULL )
- {
- ASSERT_VALID( pTabs );
- pTII = pTabs->ItemGet( LONG( lParam ) );
- ASSERT( pTII != NULL );
- ASSERT_VALID( pTII );
- nItemIndex = (LONG)lParam;
- pIconTabItemCloseButton =
- pTabs->OnTabWndQueryItemCloseButtonShape( pTII );
- if( pIconTabItemCloseButton != NULL )
- {
- rcTabItemCloseButton = pTII->CloseButtonRectGet();
- ePaintStateITICB = (CExtCmdIcon::e_paint_type_t)
- pTabs->OnTabWndQueryItemCloseButtonPaintState( pTII );
- } // if( pIconTabItemCloseButton != NULL )
- bNoPrefix = ( ( pTabs->GetTabWndStyleEx() & __ETWS_EX_NO_PREFIX ) != 0 ) ? true : false;
- } // if( pTabs != NULL )
- else
- {
- pTBB = DYNAMIC_DOWNCAST( CExtBarButton, pHelperSrc );
- #ifdef _DEBUG
- if( pTBB != NULL )
- {
- ASSERT_VALID( pTBB );
- } // if( pTBB != NULL )
- #endif // _DEBUG
- } // else from if( pTabs != NULL )
- } // if( pHelperSrc != NULL )
- LONG nSelectionIndex = -1;
- if( pTabs != NULL )
- nSelectionIndex = pTabs->SelectionGet();
- bool bInGroupFirst = false;
- bool bInGroupLast = false;
- if( bGroupedMode && pTII != NULL )
- {
- ASSERT( pTabs != NULL );
- CExtTabWnd::TAB_ITEM_INFO * pTiiFirst = pTII->GetInGroupFirst();
- CExtTabWnd::TAB_ITEM_INFO * pTiiLast = pTII->GetInGroupLast();
- ASSERT_VALID( pTiiFirst );
- ASSERT_VALID( pTiiLast );
- bInGroupFirst = ( nItemIndex == pTabs->ItemGetIndexOf( pTiiFirst ) );
- bInGroupLast = ( nItemIndex == pTabs->ItemGetIndexOf( pTiiLast ) );
- }
- bool bFirstItem = false, bLastItem = false;
- if( pTII != NULL )
- {
- ASSERT( pTabs != NULL );
- bFirstItem =
- ( nItemIndex == 0
- || ( bInGroupFirst
- && nItemIndex != nSelectionIndex
- )
- );
- bLastItem =
- ( nItemIndex == pTabs->ItemGetCount() - 1
- || ( bInGroupLast
- && nItemIndex != nSelectionIndex
- )
- );
- }
- bool bHover = false;
- bool bPressed = false;
- bool bEnabled = true;
- if( pTII != NULL )
- {
- ASSERT( pTabs != NULL );
- bEnabled = pTII->EnabledGet();
- bHover = ( pTabs->GetHoverTrackingItem() == nItemIndex ) ? true : false;
- bPressed = ( pTabs->GetPushedTrackingItem() == nItemIndex ) ? true : false;
- }
- else if( pTBB != NULL )
- {
- bEnabled = pTBB->IsEnabled();
- bHover = pTBB->IsHover();
- bPressed = pTBB->IsPressed();
- }
- CRect rcItem( rcEntireItem );
- HWND hWndOpenTheme = pTabs->GetSafeHwnd();
- if( hWndOpenTheme == NULL )
- hWndOpenTheme = ::GetDesktopWindow();
- if( g_PaintManager.m_UxTheme.OpenThemeData( hWndOpenTheme, VSCLASS_TAB ) != NULL )
- {
- INT nPartID = TABP_TABITEM;
- INT nStateID =
- (!bEnabled)
- ? TIS_DISABLED
- : bSelected
- ? TIS_SELECTED
- : bPressed
- ? TIS_FOCUSED
- : bHover
- ? TIS_HOT
- : TIS_NORMAL;
- CExtBitmap _bmp1, _bmp2;
- COLORREF * pClrSurface = NULL;
- CBitmap _bmp;
- CBitmap * pOldBmp = NULL;
- CDC dcX;
- bool bDetectedDynTPC = false;
- bDetectedDynTPC;
- #if (!defined __EXT_MFC_NO_DYNAMIC_BAR_SITE)
- if( pTII != NULL )
- {
- CObject * pObject = pTII->EventProviderGet();
- if( pObject != NULL )
- {
- CExtDynamicControlBar * pBar = DYNAMIC_DOWNCAST( CExtDynamicControlBar, pObject );
- if( pBar != NULL )
- {
- bool bFlashCaptionHighlightedState = false;
- if( pBar->FlashCaptionIsInProgress( &bFlashCaptionHighlightedState ) )
- {
- if( bFlashCaptionHighlightedState )
- {
- clrForceText = pBar->m_clrFlashCaptionText;
- clrForceTabBk = pBar->m_clrFlashCaptionBackground;
- bSelected = true;
- #if (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
- bDetectedDynTPC = true;
- #endif // (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
- }
- }
- }
- }
- }
- #endif// (!defined __EXT_MFC_NO_DYNAMIC_BAR_SITE)
- COLORREF clrColorizeTabShape = COLORREF(-1L);
- #if (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
- if( pHelperSrc != NULL
- && clrForceTabBk != COLORREF(-1L)
- && ( bDetectedDynTPC
- || pHelperSrc->IsKindOf( RUNTIME_CLASS( CExtDynTabWnd ) )
- || pHelperSrc->IsKindOf( RUNTIME_CLASS( CExtDynAutoHideArea ) )
- )
- )
- clrColorizeTabShape = clrForceTabBk;
- #endif // (!defined __EXT_MFC_NO_TAB_CONTROLBARS)
- #if (!defined __EXT_MFC_NO_TABMDI_CTRL)
- if( pHelperSrc != NULL
- && clrForceTabBk != COLORREF(-1L)
- && pHelperSrc->IsKindOf( RUNTIME_CLASS( CExtTabWnd ) )
- && ((CExtTabWnd*)pHelperSrc)->_IsMdiTabCtrl()
- )
- clrColorizeTabShape = clrForceTabBk;
- #endif // (!defined __EXT_MFC_NO_TABMDI_CTRL)
- if( bHorz )
- {
- if( bTopLeft && clrColorizeTabShape == COLORREF(-1L) )
- {
- rcItem.OffsetRect( 0, 2 );
- if( bSelected )
- rcItem.InflateRect( bFirstItem ? 0 : 2, 2, bLastItem ? 0 : 2, 2 );
- VERIFY(
- g_PaintManager.m_UxTheme.DrawBackground(
- hWndOpenTheme,
- dc.GetSafeHdc(),
- nPartID,
- nStateID,
- &rcItem,
- &rcItem
- ) == S_OK
- );
- }
- else
- {
- if( bSelected )
- rcItem.InflateRect( bFirstItem ? 0 : 2, 2, bLastItem ? 0 : 2, 2 );
- VERIFY( _bmp1.FromSurface( dc.m_hDC, rcItem ) );
- if( ! bTopLeft )
- {
- VERIFY(
- _bmp2.CreateRotated9xStack(
- _bmp1,
- 180,
- 1,
- rcItem.Width(),
- rcItem.Height(),
- false,
- false
- )
- );
- }
- else
- _bmp2 = _bmp1;
- HBITMAP hBmp = _bmp2.CreateBitmap( &pClrSurface );
- ASSERT( hBmp != NULL && pClrSurface != NULL );
- _bmp.Attach( hBmp );
- VERIFY( dcX.CreateCompatibleDC( NULL ) );
- pOldBmp = dcX.SelectObject( &_bmp );
- CRect rcItemX( 0, 0, rcItem.Width(), rcItem.Height() );
- VERIFY(
- g_PaintManager.m_UxTheme.DrawBackground(
- hWndOpenTheme,
- dcX.GetSafeHdc(),
- nPartID,
- nStateID,
- &rcItemX,
- &rcItemX
- ) == S_OK
- );
- dcX.SelectObject( pOldBmp );
- _bmp2.Empty();
- VERIFY( _bmp2.FromBitmap( hBmp ) );
- _bmp1.Empty();
- if( ! bTopLeft )
- {
- VERIFY(
- _bmp1.CreateRotated9xStack(
- _bmp2,
- 180,
- 1,
- rcItem.Width(),
- rcItem.Height(),
- false,
- false
- )
- );
- }
- else
- _bmp1 = _bmp2;
- if( clrColorizeTabShape != COLORREF(-1L) )
- {
- _bmp1.Make32();
- _bmp1.AdjustHLS( COLORREF(-1L), COLORREF(-1L), 0.0, -0.5 );
- _bmp1.MakeMono( clrColorizeTabShape );
- _bmp1.AlphaBlend( dc.m_hDC, rcItem, 64 );
- }
- else
- _bmp1.Draw( dc.m_hDC, rcItem );
- }
- } // if( bHorz )
- else
- {
- if( bTopLeft && clrColorizeTabShape == COLORREF(-1L) )
- {
- rcItem.OffsetRect( 2, 0 );
- if( bSelected )
- rcItem.InflateRect( 2, bFirstItem ? 0 : 2, 2, bLastItem ? 0 : 2 );
- VERIFY( _bmp1.FromSurface( dc.m_hDC, rcItem ) );
- VERIFY(
- _bmp2.CreateRotated9xStack(
- _bmp1,
- 90,
- 1,
- rcItem.Width(),
- rcItem.Height(),
- false,
- false
- )
- );
- HBITMAP hBmp = _bmp2.CreateBitmap( &pClrSurface );
- ASSERT( hBmp != NULL && pClrSurface != NULL );
- _bmp.Attach( hBmp );
- VERIFY( dcX.CreateCompatibleDC( NULL ) );
- pOldBmp = dcX.SelectObject( &_bmp );
- CRect rcItemX( 0, 0, rcItem.Height(), rcItem.Width() );
- VERIFY(
- g_PaintManager.m_UxTheme.DrawBackground(
- hWndOpenTheme,
- dcX.GetSafeHdc(),
- nPartID,
- nStateID,
- &rcItemX,
- &rcItemX
- ) == S_OK
- );
- dcX.SelectObject( pOldBmp );
- _bmp2.Empty();
- VERIFY( _bmp2.FromBitmap( hBmp ) );
- _bmp1.Empty();
- VERIFY(
- _bmp1.CreateRotated9xStack(
- _bmp2,
- 270,
- 1,
- rcItem.Height(),
- rcItem.Width(),
- false,
- false
- )
- );
- _bmp1.Draw( dc.m_hDC, rcItem );
- }
- else
- {
- if( bSelected )
- rcItem.InflateRect( 2, bFirstItem ? 0 : 2, 2, bLastItem ? 0 : 2 );
- VERIFY( _bmp1.FromSurface( dc.m_hDC, rcItem ) );
- if( ! bTopLeft )
- {
- VERIFY(
- _bmp2.CreateRotated9xStack(
- _bmp1,
- 270,
- 1,
- rcItem.Width(),
- rcItem.Height(),
- false,
- false
- )
- );
- }
- else
- _bmp2 = _bmp1;
- HBITMAP hBmp = _bmp2.CreateBitmap( &pClrSurface );
- ASSERT( hBmp != NULL && pClrSurface != NULL );
- _bmp.Attach( hBmp );
- VERIFY( dcX.CreateCompatibleDC( NULL ) );
- pOldBmp = dcX.SelectObject( &_bmp );
- CRect rcItemX( 0, 0, rcItem.Height(), rcItem.Width() );
- VERIFY(
- g_PaintManager.m_UxTheme.DrawBackground(
- hWndOpenTheme,
- dcX.GetSafeHdc(),
- nPartID,
- nStateID,
- &rcItemX,
- &rcItemX
- ) == S_OK
- );
- dcX.SelectObject( pOldBmp );
- _bmp2.Empty();
- VERIFY( _bmp2.FromBitmap( hBmp ) );
- _bmp1.Empty();
- if( ! bTopLeft )
- {
- VERIFY(
- _bmp1.CreateRotated9xStack(
- _bmp2,
- 90,
- 1,
- rcItem.Height(),
- rcItem.Width(),
- false,
- false
- )
- );
- }
- else
- _bmp1 = _bmp2;
- if( clrColorizeTabShape != COLORREF(-1L) )
- {
- _bmp1.Make32();
- _bmp1.AdjustHLS( COLORREF(-1L), COLORREF(-1L), 0.0, -0.5 );
- _bmp1.MakeMono( clrColorizeTabShape );
- _bmp1.AlphaBlend( dc.m_hDC, rcItem, 64 );
- }
- else
- _bmp1.Draw( dc.m_hDC, rcItem );
- }
- } // else if( bHorz )
-
- if( _bmp.GetSafeHandle() != NULL )
- _bmp.DeleteObject();
-
- if( dcX.GetSafeHdc() != NULL )
- dcX.DeleteDC();
- g_PaintManager.m_UxTheme.CloseThemeData();
- } // if( g_PaintManager.m_UxTheme.OpenThemeData( ...
- COLORREF clrText = clrForceText;
- if( clrText == COLORREF(-1L) )
- clrText =
- ::GetSysColor( bEnabled ? COLOR_BTNTEXT : COLOR_GRAYTEXT );
- #define __EXTTAB_INDENT_TOP 2
- #define __EXTTAB_INDENT_BOTTOM 2
- #define __EXTTAB_INDENT_LEFT 2
- #define __EXTTAB_INDENT_RIGHT 2
- rcItem.DeflateRect(
- bHorz
- ? __EXTTAB_INDENT_LEFT
- : __EXTTAB_INDENT_TOP,
- bHorz
- ? __EXTTAB_INDENT_TOP
- : __EXTTAB_INDENT_LEFT,
- bHorz
- ? __EXTTAB_INDENT_RIGHT
- : __EXTTAB_INDENT_TOP,
- bHorz
- ? __EXTTAB_INDENT_BOTTOM
- : __EXTTAB_INDENT_RIGHT
- );
-
- CSize _sizeIcon( 0, 0 );
- bool bDrawIcon = (
- pIcon != NULL
- && (!pIcon->IsEmpty())
- && ( pTabs == NULL || (pTabs->GetTabWndStyle()&__ETWS_HIDE_ICONS) == 0 )
- );
- if( bDrawIcon )
- {
- _sizeIcon = pIcon->GetSize();
- ASSERT( _sizeIcon.cx > 0 && _sizeIcon.cy > 0 );
- }
- CRect rcItemForIcon( rcItem );
- if( bDrawIcon
- && _sizeIcon.cx > 0
- && _sizeIcon.cy > 0
- )
- {
- // rcItemForIcon.DeflateRect(
- // bHorz ? 0 : ( rcItem.Width() - _sizeIcon.cx),
- // bHorz ? ( rcItem.Height() - _sizeIcon.cy) : 0
- // );
- rcItemForIcon.right = rcItemForIcon.left + _sizeIcon.cx;
- rcItemForIcon.bottom = rcItemForIcon.top + _sizeIcon.cy;
- rcItemForIcon.OffsetRect(
- bHorz ? 0 : ((rcItem.Width() - _sizeIcon.cx) / 2),
- bHorz ? ((rcItem.Height() - _sizeIcon.cy) / 2) : 0
- );
- if( rcItemForIcon.left < (rcItem.left+1) )
- rcItemForIcon.left = (rcItem.left+1);
- if( rcItemForIcon.right < (rcItem.right-1) )
- rcItemForIcon.right = (rcItem.right-1);
- if( rcItemForIcon.top < (rcItem.top+1) )
- rcItemForIcon.top = (rcItem.top+1);
- if( rcItemForIcon.bottom < (rcItem.bottom-1) )
- rcItemForIcon.bottom = (rcItem.bottom-1);
- }
- CExtSafeString sItemText( (sText == NULL) ? _T("") : sText );
- // IMPORTANT: the rcText calculation fixed by Genka
- CRect rcText(
- rcItem.left // rcItemForIcon.left
- + ( bHorz
- ? (_sizeIcon.cx +
- ((_sizeIcon.cx > 0) ? __EXTTAB_MARGIN_ICON2TEXT_X : 0)
- )
- : 0
- ),
- rcItem.top // rcItemForIcon.left
- + ( bHorz
- ? 0
- : (_sizeIcon.cy +
- ((_sizeIcon.cy > 0) ? __EXTTAB_MARGIN_ICON2TEXT_Y : 0)
- )
- ),
- rcItem.right,
- rcItem.bottom
- );
- if( !bHorz )
- {
- if( pIconTabItemCloseButton != NULL )
- rcText.bottom = min( rcText.bottom, rcTabItemCloseButton.top );
- int nWidth0 = rcText.Width();
- int nWidth1 = rcItem.Width() + __EXTTAB_MARGIN_ICON2TEXT_X*2;
- if( nWidth1 > nWidth0 )
- {
- if( bInvertedVerticalMode )
- {
- //rcText.right -= __EXTTAB_MARGIN_ICON2TEXT_X;
- rcText.left = rcText.right - nWidth1;
- } // if( bInvertedVerticalMode )
- else
- {
- //rcText.left += __EXTTAB_MARGIN_ICON2TEXT_X;
- rcText.right = rcText.left + nWidth1;
- } // else from if( bInvertedVerticalMode )
- } // if( nWidth1 > nWidth0 )
- } // if( !bHorz )
- else
- {
- if( pIconTabItemCloseButton != NULL )
- rcText.right = min( rcText.right, rcTabItemCloseButton.left );
- }
- bool bDrawText = ( ( ! sItemText.IsEmpty() ) && rcText.Width() > 0 && rcText.Height() > 0 ) ? true : false;
- INT nIconAlignment = __ALIGN_HORIZ_LEFT | __ALIGN_VERT_TOP;
- if( (!bDrawText) && !( bGroupedMode && (!bInGroupActive) ) )
- {
- if( bCenteredText )
- nIconAlignment = __ALIGN_HORIZ_CENTER|__ALIGN_VERT_CENTER;
- else
- rcItemForIcon.OffsetRect(
- bHorz ? (rcItem.Width() - _sizeIcon.cx)/2 : 0,
- bHorz ? 0 : (rcItem.Height() - _sizeIcon.cy)/2
- );
- }
- if( bDrawIcon )
- {
- if( (bHorz && rcItemForIcon.Width() >= _sizeIcon.cx )
- || (!bHorz && rcItemForIcon.Height() >= _sizeIcon.cy)
- )
- {
- PaintIcon(
- dc,
- true,
- pIcon,
- rcItemForIcon,
- false,
- bEnabled,
- false,
- nIconAlignment
- );
- }
- } // if( bDrawIcon )
- if( bDrawText )
- { // if we have sense to paint text on tab item
- ASSERT( pFont != NULL );
- ASSERT( pFont->GetSafeHandle() != NULL );
- COLORREF clrOldText = dc.SetTextColor( clrText );
- INT nOldBkMode = dc.SetBkMode( TRANSPARENT );
-
- CFont * pOldFont = dc.SelectObject( pFont );
- if( !bHorz )
- {
- if( bCenteredText )
- rcText.OffsetRect(
- 0,
- ( rcText.Height() - sizeTextMeasured.cx ) / 2
- );
- int nTextLength = sItemText.GetLength();
- int nAmpIndex = bNoPrefix ? (-1) : int( sItemText.Find( _T('&') ) );
- CExtSafeString sBtn;
- if( nAmpIndex < 0 || bNoPrefix )
- sBtn = sItemText;
- else
- sBtn =
- sItemText.Left( nAmpIndex )
- + sItemText.Right( nTextLength - ( nAmpIndex + 1 ) );
- if( ! bNoPrefix )
- {
- static TCHAR stat_strDummyAmpSeq[] = _T("