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

Graph program

Development Platform:

Visual C++

  1. // PropTreeItemCombo.cpp : implementation file
  2. //
  3. //  Copyright (C) 1998-2001 Scott Ramsay
  4. // sramsay@gonavi.com
  5. // http://www.gonavi.com
  6. //
  7. //  This material is provided "as is", with absolutely no warranty expressed
  8. //  or implied. Any use is at your own risk.
  9. // 
  10. //  Permission to use or copy this software for any purpose is hereby granted 
  11. //  without fee, provided the above notices are retained on all copies.
  12. //  Permission to modify the code and to distribute modified code is granted,
  13. //  provided the above notices are retained, and a notice that the code was
  14. //  modified is included with the above copyright notice.
  15. // 
  16. // If you use this code, drop me an email.  I'd like to know if you find the code
  17. // useful.
  18. #include "stdafx.h"
  19. #include "EGPropertyGrid.h"
  20. //#include "Resource.h"
  21. #include "EGPropertyGridItemCombo.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. #define DROPDOWN_HEIGHT 100
  28. /////////////////////////////////////////////////////////////////////////////
  29. // CEGPropertyGridItemCombo
  30. CEGPropertyGridItemCombo::CEGPropertyGridItemCombo() :
  31. m_lComboData(0),
  32. m_nDropHeight(DROPDOWN_HEIGHT)
  33. {
  34. }
  35. CEGPropertyGridItemCombo::~CEGPropertyGridItemCombo()
  36. {
  37. }
  38. BEGIN_MESSAGE_MAP(CEGPropertyGridItemCombo, CComboBox)
  39. //{{AFX_MSG_MAP(CEGPropertyGridItemCombo)
  40. ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
  41. ON_CONTROL_REFLECT(CBN_KILLFOCUS, OnKillfocus)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // CEGPropertyGridItemCombo message handlers
  46. void CEGPropertyGridItemCombo::DrawAttribute(CDC* pDC, const RECT& rc)
  47. {
  48. ASSERT(m_pProp!=NULL);
  49. // verify the window has been created
  50. if (!IsWindow(m_hWnd))
  51. {
  52. TRACE0("CEGPropertyGridItemCombo::DrawAttribute() - The window has not been createdn");
  53. return;
  54. }
  55. pDC->SelectObject(IsReadOnly() ? m_pProp->GetNormalFont() : m_pProp->GetBoldFont());
  56. pDC->SetTextColor(RGB(0,0,0));
  57. pDC->SetBkMode(TRANSPARENT);
  58. CRect r = rc;
  59. CString s;
  60. LONG idx;
  61. if ((idx = GetCurSel())!=CB_ERR)
  62. GetLBText(idx, s);
  63. else
  64. s = _T("");
  65. pDC->DrawText(s, r, DT_SINGLELINE|DT_VCENTER);
  66. }
  67. LPARAM CEGPropertyGridItemCombo::GetItemValue()
  68. {
  69. return m_lComboData;
  70. }
  71. void CEGPropertyGridItemCombo::SetItemValue(LPARAM lParam)
  72. {
  73. m_lComboData = lParam;
  74. OnRefresh();
  75. }
  76. void CEGPropertyGridItemCombo::OnMove()
  77. {
  78. if (IsWindow(m_hWnd) && IsWindowVisible())
  79. SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width() + 1, m_rc.Height(), SWP_NOZORDER|SWP_SHOWWINDOW);
  80. }
  81. void CEGPropertyGridItemCombo::OnRefresh()
  82. {
  83. LONG idx = FindCBData(m_lComboData);
  84. if (idx!=CB_ERR)
  85. SetCurSel(idx);
  86. }
  87. void CEGPropertyGridItemCombo::OnCommit()
  88. {
  89. LONG idx;
  90. // store combo box item data
  91. if ((idx = GetCurSel())==CB_ERR)
  92. m_lComboData = 0;
  93. else
  94. m_lComboData = (LPARAM)GetItemData(idx);
  95. ShowWindow(SW_HIDE);
  96. }
  97. void CEGPropertyGridItemCombo::OnActivate()
  98. {
  99. // activate the combo box
  100. SetWindowPos(NULL, m_rc.left, m_rc.top, m_rc.Width() + 1, m_rc.Height() + m_nDropHeight, SWP_NOZORDER|SWP_SHOWWINDOW);
  101. SetFocus();
  102. if (GetCount())
  103. ShowDropDown(TRUE);
  104. }
  105. BOOL CEGPropertyGridItemCombo::CreateComboBox(DWORD dwStyle)
  106. {
  107. ASSERT(m_pProp!=NULL);
  108. if (IsWindow(m_hWnd))
  109. DestroyWindow();
  110. // force as not visible child window
  111. dwStyle = (WS_CHILD|WS_VSCROLL|dwStyle) & ~WS_VISIBLE;
  112. if (!Create(dwStyle, CRect(0,0,0,0), m_pProp->GetCtrlParent(), GetCtrlID()))
  113. {
  114. TRACE0("CEGPropertyGridItemCombo::CreateComboBox() - failed to create combo boxn");
  115. return FALSE;
  116. }
  117. SendMessage(WM_SETFONT, (WPARAM)m_pProp->GetNormalFont()->m_hObject);
  118. return TRUE;
  119. }
  120. BOOL CEGPropertyGridItemCombo::CreateComboBoxBool()
  121. {
  122. ASSERT(m_pProp!=NULL);
  123. if (IsWindow(m_hWnd))
  124. DestroyWindow();
  125. // force as a non-visible child window
  126. DWORD dwStyle = WS_CHILD|WS_VSCROLL|CBS_SORT|CBS_DROPDOWNLIST;
  127. if (!Create(dwStyle, CRect(0,0,0,0), m_pProp->GetCtrlParent(), GetCtrlID()))
  128. {
  129. TRACE0("CEGPropertyGridItemCombo::CreateComboBoxBool() - failed to create combo boxn");
  130. return FALSE;
  131. }
  132. SendMessage(WM_SETFONT, (WPARAM)m_pProp->GetNormalFont()->m_hObject);
  133. // file the combo box
  134. LONG idx;
  135. CString s;
  136. //s.LoadString(IDS_TRUE);
  137. s = _T("泥");
  138. idx = AddString(s);
  139. SetItemData(idx, TRUE);
  140. // s.LoadString(IDS_FALSE);
  141. s = _T("湾