EGTabCtrl.cpp
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 4k
Category:

Graph program

Development Platform:

Visual C++

  1. // BaseTabCtrl.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "EGTabCtrl.h"
  5. #include "EGMenu.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. #define PADDING 3
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CEGTabCtrl
  14. CEGTabCtrl::CEGTabCtrl( )
  15. {
  16. m_clrBack = RGB( 247, 243, 233 );
  17. m_clrInactiveTab = RGB( 247, 243, 233 );
  18. m_clrActiveTab = ::GetSysColor( COLOR_BTNFACE );
  19. m_clrInactiveText = ::GetSysColor( COLOR_3DSHADOW );
  20. m_clrActiveText = ::GetSysColor( COLOR_WINDOWTEXT );
  21. m_clr3DLight = ::GetSysColor( COLOR_3DHILIGHT );
  22. m_clr3DShadow = ::GetSysColor( COLOR_WINDOWTEXT );
  23. m_clrSeparator = ::GetSysColor( COLOR_3DSHADOW );
  24. m_bCustomDraw = FALSE;
  25. }
  26. CEGTabCtrl::~CEGTabCtrl()
  27. {
  28. }
  29. BEGIN_MESSAGE_MAP(CEGTabCtrl, CTabCtrl)
  30. ON_WM_ERASEBKGND()
  31. ON_WM_PAINT()
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CBaseTabCtrl message handlers
  35. BOOL CEGTabCtrl::SetCustomDraw( BOOL bValue )
  36. {
  37. m_bCustomDraw = bValue;
  38. if (GetSafeHwnd()) {
  39. if (m_bCustomDraw ) 
  40. ModifyStyle( 0, TCS_OWNERDRAWFIXED );
  41. else
  42. ModifyStyle( TCS_OWNERDRAWFIXED, 0 );
  43. Invalidate();
  44. }
  45. return TRUE;
  46. }
  47. void CEGTabCtrl::DrawItem( CDC* pDC, CRect* lprcBorder, int nTab, BOOL bSelected, BOOL bFocused )
  48. {
  49. ASSERT ( m_bCustomDraw );
  50. CString sTemp;
  51. TC_ITEM     tci;
  52. tci.mask        = TCIF_TEXT | TCIF_IMAGE;
  53. tci.pszText     = sTemp.GetBuffer(100);
  54. tci.cchTextMax  = 99;
  55. GetItem(nTab, &tci);
  56. sTemp.ReleaseBuffer();
  57. //lprcBorder->bottom ++;
  58. //if( bSelected ) {
  59. // lprcBorder->top -=2;
  60. // lprcBorder->right +=2;
  61. // if ( nTab > 0 )
  62. // lprcBorder->left -=2;
  63. //}
  64. themeData.DrawTab( pDC, lprcBorder, NULL, (TCHAR*)(LPCTSTR)sTemp, ALIGN_TOP, (bSelected ? STYLE_ACTIVE : 0), themeData.clrBtnFace );
  65. }
  66. void CEGTabCtrl::DrawMainBorder( CDC* pDC, CRect* lprcBorder )
  67. {
  68. ASSERT ( m_bCustomDraw );
  69. pDC->Draw3dRect( lprcBorder, m_clrInactiveText, m_clrInactiveText );
  70. }
  71. void CEGTabCtrl::PreSubclassWindow() 
  72. {
  73. CTabCtrl::PreSubclassWindow();
  74. if ( m_bCustomDraw ) 
  75. ModifyStyle(0, TCS_OWNERDRAWFIXED);
  76. }
  77. void CEGTabCtrl::DrawHeaderBk( CDC* pDC, CRect* lprcHeader ){
  78. pDC->FillSolidRect( lprcHeader, m_clrBack );
  79. pDC->Draw3dRect( lprcHeader, m_clrInactiveText, m_clr3DLight );
  80. }
  81. BOOL CEGTabCtrl::OnEraseBkgnd(CDC* pDC) 
  82. {
  83. if ( !m_bCustomDraw )
  84. return CTabCtrl::OnEraseBkgnd(pDC);
  85. if  ( GetItemCount() > 0 ) {
  86. CRect rcClient, rcTab;
  87. GetClientRect(rcClient);
  88. rcTab = rcClient;
  89. GetItemRect(0, rcTab);
  90. rcClient.bottom = rcTab.bottom + 3;
  91. themeData.DrawTabCtrlBK( pDC, &rcClient, ALIGN_TOP, TRUE, themeData.clrBtnFace );
  92. }
  93. return TRUE;
  94. }
  95. void CEGTabCtrl::OnPaint() 
  96. {
  97. if ( !m_bCustomDraw ) {
  98. Default();
  99. return;
  100. }
  101. CPaintDC dc(this); // device context for painting
  102. CRect rcClient, rcItem;
  103. // prepare dc
  104. dc.SelectObject(GetFont());
  105. DRAWITEMSTRUCT dis;
  106. dis.CtlType = ODT_TAB;
  107. dis.CtlID = GetDlgCtrlID();
  108. dis.hwndItem = GetSafeHwnd();
  109. dis.hDC = dc.GetSafeHdc();
  110. dis.itemAction = ODA_DRAWENTIRE;
  111. int nTab = GetItemCount();
  112. // draw the rest of the border
  113. GetClientRect(&rcClient);
  114. rcItem = rcClient;
  115. if ( 0 == nTab ) {
  116. DrawMainBorder( &dc, &rcItem );
  117. } else {
  118. AdjustRect(FALSE, rcItem);
  119. rcItem.top += 2;
  120. rcItem.left = rcClient.left;
  121. rcItem.right = rcClient.right;
  122. rcItem.bottom = rcClient.bottom;
  123. DrawMainBorder( &dc, &rcItem );
  124. }
  125. // paint the tabs first and then the borders
  126. int nSel = GetCurSel();
  127. int nFocus = ::GetFocus() == m_hWnd ? GetCurFocus() : -1;
  128. if (!nTab) // no pages added
  129. return;
  130. while (nTab--)
  131. if (nTab != nSel)
  132. if ( GetItemRect(nTab, &rcItem) )
  133. DrawItem( &dc, &rcItem, nTab, nTab == nFocus );
  134. // now selected tab
  135. if ( GetItemRect(nSel, &rcItem) )
  136. DrawItem( &dc, &rcItem, nSel, TRUE, nSel == nFocus  );
  137. }