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

Graph program

Development Platform:

Visual C++

  1. #include "stdafx.h"
  2. #include "OptionTreeItemLineTypeComboBox.h"
  3. #include "..//..//Drawer.h"
  4. // Added Headers
  5. #include "OptionTree.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // COptionTreeItemLineTypeComboBox
  13. COptionTreeItemLineTypeComboBox::COptionTreeItemLineTypeComboBox()
  14. {
  15. // Initialize variables
  16. m_bFocus = FALSE;
  17. m_lDropDownHeight = OT_COMBO_DROPDOWNHEIGHT;
  18. m_line_type = 0;
  19. // Set item type
  20. SetItemType(OT_ITEM_COMBOBOX);
  21. }
  22. COptionTreeItemLineTypeComboBox::~COptionTreeItemLineTypeComboBox()
  23. {
  24. }
  25. BEGIN_MESSAGE_MAP(COptionTreeItemLineTypeComboBox, CLineStyleCombo)
  26. //{{AFX_MSG_MAP(COptionTreeItemLineTypeComboBox)
  27. ON_WM_SETFOCUS()
  28. ON_WM_KILLFOCUS()
  29. //}}AFX_MSG_MAP
  30. END_MESSAGE_MAP()
  31. /////////////////////////////////////////////////////////////////////////////
  32. // COptionTreeItemLineTypeComboBox message handlers
  33. void COptionTreeItemLineTypeComboBox::DrawAttribute(CDC *pDC, const RECT &rcRect)
  34. {
  35. // If we don't have focus, text is drawn.
  36. if (m_bFocus == TRUE)
  37. {
  38. return;
  39. }
  40. // Make sure options aren't NULL
  41. if (m_otOption == NULL)
  42. {
  43. return;
  44. }
  45. // Make sure there is a window
  46. if (!IsWindow(GetSafeHwnd()))
  47. {
  48. return;
  49. }
  50. // Set window position
  51. if (IsWindow(GetSafeHwnd()))
  52. {
  53. MoveWindow(m_rcAttribute.left, m_rcAttribute.top, m_rcAttribute.Width(), m_rcAttribute.Height());
  54. }
  55. CRect rrr = rcRect;
  56. COLORREF crNormal = GetSysColor( COLOR_WINDOW );
  57. pDC->SetBkColor( crNormal ); // Set BG To Highlight Color
  58. pDC->FillSolidRect( &rrr, crNormal ); // Erase Item
  59. CPen penHighlight(PS_SOLID, 1, RGB(0,0,0));
  60. CPen* pOldPen = pDC->SelectObject(&penHighlight);
  61. Drawer::DrawStylingLine(Drawer::GetLineTypeByIndex(m_line_type),
  62. pDC,CPoint(rcRect.left,
  63. rcRect.top+(rcRect.bottom-rcRect.top)/2),
  64. rcRect.right-rcRect.left);
  65. pDC->SelectObject(pOldPen);
  66. }
  67. void COptionTreeItemLineTypeComboBox::OnCommit()
  68. {
  69. // Hide edit control
  70. if (IsWindow(GetSafeHwnd()))
  71. {
  72. // -- Show window
  73. ShowWindow(SW_HIDE);
  74. }
  75. m_line_type = GetCurSel();
  76. }
  77. void COptionTreeItemLineTypeComboBox::OnRefresh()
  78. {
  79. // Set the window text
  80. if (IsWindow(GetSafeHwnd()))
  81. {
  82. MoveWindow(m_rcAttribute.left, m_rcAttribute.top, m_rcAttribute.Width(), m_rcAttribute.Height());
  83. }
  84. }
  85. void COptionTreeItemLineTypeComboBox::OnMove()
  86. {
  87. // Set window position
  88. if (IsWindow(GetSafeHwnd()))
  89. {
  90. MoveWindow(m_rcAttribute.left, m_rcAttribute.top, m_rcAttribute.Width(), m_rcAttribute.Height());
  91. }
  92. // Hide window
  93. if (m_bFocus == FALSE && IsWindow(GetSafeHwnd()))
  94. {
  95. // -- Show window
  96. ShowWindow(SW_HIDE);
  97. }
  98. }
  99. void COptionTreeItemLineTypeComboBox::OnActivate()
  100. {
  101. // Make sure window is valid
  102. if (IsWindow(GetSafeHwnd()))
  103. {
  104. // -- Show window
  105. ShowWindow(SW_SHOW);
  106. // -- Set window position
  107. MoveWindow(m_rcAttribute.left, m_rcAttribute.top, m_rcAttribute.Width(), m_rcAttribute.Height() + m_lDropDownHeight);
  108. // -- Set focus
  109. SetFocus();
  110. SetCurSel(m_line_type);
  111. }
  112. }
  113. void COptionTreeItemLineTypeComboBox::OnSetFocus(CWnd* pOldWnd) 
  114. {
  115. // Mark focus
  116. m_bFocus = TRUE;
  117. CLineStyleCombo::OnSetFocus(pOldWnd);
  118. }
  119. void COptionTreeItemLineTypeComboBox::OnKillFocus(CWnd* pNewWnd) 
  120. {
  121. // Validate
  122. if (m_otOption == NULL)
  123. {
  124. CLineStyleCombo::OnKillFocus(pNewWnd);
  125. return;
  126. }
  127. // See if new window is tree of list
  128. if (m_otOption->IsChild(pNewWnd) == TRUE)
  129. {
  130. // -- Mark focus
  131. m_bFocus = FALSE;
  132. // -- Commit changes
  133. CommitChanges();
  134. }
  135. CLineStyleCombo::OnKillFocus(pNewWnd);
  136. }
  137. BOOL COptionTreeItemLineTypeComboBox::CreateComboItem(DWORD dwAddStyle)
  138. {
  139. // Declare variables
  140. DWORD dwStyle = WS_CHILD | WS_VISIBLE | 
  141. CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED|WS_VSCROLL;
  142. BOOL bRet = FALSE;
  143. // Make sure options is not NULL
  144. if (m_otOption == NULL)
  145. {
  146. return FALSE;
  147. }
  148. // Create edit control
  149. if (!IsWindow(GetSafeHwnd()))
  150. {
  151. // -- Add style
  152. if (dwAddStyle != 0)
  153. {
  154. dwStyle |= dwAddStyle;
  155. }
  156. // -- Create the combo box
  157. bRet = Create(dwStyle, m_rcAttribute, m_otOption->GetCtrlParent(), GetCtrlID());
  158. // -- Setup combo
  159. if (bRet == TRUE)
  160. {
  161. // -- -- Set font
  162. SetFont(m_otOption->GetNormalFont(), TRUE);
  163. // -- -- Set window position
  164. MoveWindow(m_rcAttribute.left, m_rcAttribute.top, m_rcAttribute.Width(), m_rcAttribute.Height());
  165. // -- -- Hide window
  166. ShowWindow(SW_HIDE);
  167. }
  168. }
  169. return bRet;
  170. }
  171. void COptionTreeItemLineTypeComboBox::SetDropDownHeight(long lHeight)
  172. {
  173. // Save variable
  174. m_lDropDownHeight = lHeight;
  175. }
  176. long COptionTreeItemLineTypeComboBox::GetDropDownHeight()
  177. {
  178. // Return variable
  179. return m_lDropDownHeight;
  180. }
  181. void COptionTreeItemLineTypeComboBox::CleanDestroyWindow()
  182. {
  183. // Destroy window
  184. if (IsWindow(GetSafeHwnd()))
  185. {
  186. // -- Destroy window
  187. DestroyWindow();
  188. }
  189. }
  190. void COptionTreeItemLineTypeComboBox::OnDeSelect()
  191. {
  192. // Hide window
  193. if (IsWindow(GetSafeHwnd()))
  194. {
  195. // -- Show window
  196. ShowWindow(SW_HIDE);
  197. }
  198. }
  199. void COptionTreeItemLineTypeComboBox::OnSelect()
  200. {
  201. // Do nothing here
  202. }