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

Graph program

Development Platform:

Visual C++

  1. // COptionTree
  2. //
  3. // License
  4. // -------
  5. // This code is provided "as is" with no expressed or implied warranty.
  6. // 
  7. // You may use this code in a commercial product with or without acknowledgement.
  8. // However you may not sell this code or any modification of this code, this includes 
  9. // commercial libraries and anything else for profit.
  10. //
  11. // I would appreciate a notification of any bugs or bug fixes to help the control grow.
  12. //
  13. // History:
  14. // --------
  15. // See License.txt for full history information.
  16. //
  17. //
  18. // Copyright (c) 1999-2002 
  19. // ComputerSmarts.net 
  20. // mattrmiller@computersmarts.net
  21. #include "stdafx.h"
  22. #include "OptionTreeInfo.h"
  23. // Added Headers
  24. #include "OptionTree.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // COptionTreeInfo
  32. COptionTreeInfo::COptionTreeInfo()
  33. {
  34. // Initialize variables
  35. m_otOption = NULL;
  36. }
  37. COptionTreeInfo::~COptionTreeInfo()
  38. {
  39. }
  40. BEGIN_MESSAGE_MAP(COptionTreeInfo, CStatic)
  41. //{{AFX_MSG_MAP(COptionTreeInfo)
  42. ON_WM_PAINT()
  43. ON_WM_ERASEBKGND()
  44. //}}AFX_MSG_MAP
  45. END_MESSAGE_MAP()
  46. /////////////////////////////////////////////////////////////////////////////
  47. // COptionTreeInfo message handlers
  48. void COptionTreeInfo::OnPaint() 
  49. {
  50. // Make sure option is valid
  51. if (m_otOption == NULL)
  52. {
  53. return;
  54. }
  55. // Declare variables
  56. CPaintDC dc(this);
  57. CRect rcClient, rcText, rcOrgClient;
  58. CDC* pDCMem = new CDC;
  59. CBitmap bpMem;
  60. CBitmap *bmOld;
  61. CBrush brBack, *brOldBrush;
  62. COptionTreeItem *otiItem;
  63. COLORREF crOld;
  64. int nOldBack;
  65. HGDIOBJ hOld;
  66. CString strLabel, strInfo;
  67. // Get client rectangle
  68. GetClientRect(rcClient);
  69. rcOrgClient = rcClient;
  70. // Create pens and brushes
  71. brBack.CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  72. // Create DC
  73. pDCMem->CreateCompatibleDC(&dc);
  74. // Create bitmap
  75. bpMem.CreateCompatibleBitmap(&dc, rcClient.Width(), rcClient.Height());
  76. // Select bitmap
  77. bmOld = pDCMem->SelectObject(&bpMem);
  78. // Select brush
  79. brOldBrush = pDCMem->SelectObject(&brBack);
  80. // Paint the rectangle
  81. pDCMem->PatBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), PATCOPY);
  82. // Draw the edge
  83. pDCMem->DrawEdge(&rcClient, BDR_SUNKENOUTER, BF_RECT);
  84. // Deflate client rectangle
  85. rcClient.DeflateRect(4, 4);
  86. // Get the focused item
  87. otiItem = m_otOption->GetFocusedItem();
  88. // Set the text color
  89. if (m_otOption->IsWindowEnabled() == FALSE)
  90. {
  91. crOld = pDCMem->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
  92. }
  93. else
  94. {
  95. crOld = pDCMem->SetTextColor(GetSysColor(COLOR_BTNTEXT));
  96. }
  97. // Set the background mode
  98. nOldBack = pDCMem->SetBkMode(TRANSPARENT);
  99. // See if we have a focused item and get text
  100. // -- Default text
  101. if (otiItem == NULL)
  102. {
  103. if (m_otOption->GetDefInfoTextNoSel() == TRUE)
  104. {
  105. strLabel = OT_DEFLABEL;
  106. strInfo = OT_DEFINFO;
  107. }
  108. }
  109. // -- Items text
  110. else
  111. {
  112. strLabel = otiItem->GetLabelText();
  113. strInfo = otiItem->GetInfoText();
  114. }
  115. // Select the bold font
  116. hOld = pDCMem->SelectObject(m_otOption->GetBoldFont());
  117. // Calculate label rectangle
  118. rcText = rcClient;
  119. // Draw label
  120. pDCMem->DrawText(strLabel, &rcText, DT_SINGLELINE | DT_CALCRECT);
  121. pDCMem->DrawText(strLabel, &rcText, DT_SINGLELINE);
  122. // Select normal font
  123. pDCMem->SelectObject(m_otOption->GetNormalFont());
  124. // Calculate label rectangle
  125. rcText.top = rcText.bottom;
  126. rcText.bottom = rcClient.bottom;
  127. rcText.right = rcClient.right;
  128. // Draw info
  129. pDCMem->DrawText(strInfo, &rcText, DT_WORDBREAK);
  130. // Copy to screen
  131. dc.BitBlt(0, 0, rcOrgClient.Width(), rcOrgClient.Height(), pDCMem, 0, 0, SRCCOPY);
  132. // Restore the old GDI objects
  133. pDCMem->SelectObject(hOld);
  134. pDCMem->SelectObject(bmOld);
  135. pDCMem->SelectObject(brOldBrush);
  136. pDCMem->SetTextColor(crOld);
  137. pDCMem->SetBkMode(nOldBack);
  138. // Delete objects
  139. if (brBack.GetSafeHandle() != NULL)
  140. {
  141. brBack.DeleteObject();
  142. }
  143. if (pDCMem->GetSafeHdc() != NULL)
  144. {
  145. pDCMem->DeleteDC();
  146. }
  147. delete pDCMem;
  148. if (bpMem.GetSafeHandle() != NULL)
  149. {
  150. bpMem.DeleteObject();
  151. }
  152. }
  153. void COptionTreeInfo::SetOptionsOwner(COptionTree *otOption)
  154. {
  155. // Save pointer
  156. m_otOption = otOption;
  157. }
  158. BOOL COptionTreeInfo::OnEraseBkgnd(CDC* pDC) 
  159. {
  160. // Ha, Ha
  161. return FALSE;
  162. }