ComboBoxSearch.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // ComboBoxSearch.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CP_Main.h"
  5. #include "ComboBoxSearch.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CComboBoxSearch
  13. CComboBoxSearch::CComboBoxSearch()
  14. {
  15. m_bShowingDropDown = FALSE;
  16. }
  17. CComboBoxSearch::~CComboBoxSearch()
  18. {
  19. }
  20. BEGIN_MESSAGE_MAP(CComboBoxSearch, CComboBox)
  21. //{{AFX_MSG_MAP(CComboBoxSearch)
  22. ON_CONTROL_REFLECT(CBN_DROPDOWN, OnDropdown)
  23. ON_CONTROL_REFLECT(CBN_SELENDCANCEL, OnSelendcancel)
  24. ON_CONTROL_REFLECT(CBN_SELENDOK, OnSelendok)
  25. //}}AFX_MSG_MAP
  26. END_MESSAGE_MAP()
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CComboBoxSearch message handlers
  29. void CComboBoxSearch::OnDropdown()
  30. {
  31. m_bShowingDropDown = TRUE;
  32. SetCurSel(0);
  33. }
  34. void CComboBoxSearch::OnSelendcancel()
  35. {
  36. m_bShowingDropDown = FALSE;
  37. }
  38. void CComboBoxSearch::OnSelendok()
  39. {
  40. m_bShowingDropDown = FALSE;
  41. }
  42. BOOL CComboBoxSearch::PreTranslateMessage(MSG* pMsg)
  43. {
  44. switch(pMsg->message)
  45. {
  46. case WM_KEYDOWN:
  47. {
  48. if(pMsg->wParam == VK_RETURN && m_bShowingDropDown == FALSE)
  49. {
  50. CWnd *pWnd = GetParent();
  51. if(pWnd)
  52. {
  53. if(GetCurSel() == -1)
  54. {
  55. //Add the text to the combo
  56. CString csText;
  57. GetWindowText(csText);
  58. int nRet = InsertString(0, csText);
  59. SetCurSel(nRet);
  60. }
  61. if(g_Opt.m_bFindAsYouType)
  62. {
  63. pWnd->SendMessage(NM_SELECT, 0, 0);
  64. }
  65. else
  66. {
  67. //Send a message to the parent to refill the lb from the search
  68. pWnd->PostMessage(CB_SEARCH, 0, 0);
  69. }
  70. }
  71. return TRUE;
  72. }
  73. else if (pMsg->wParam == VK_DOWN ||
  74. pMsg->wParam == VK_UP ||
  75. pMsg->wParam == VK_F3)
  76. {
  77. if(g_Opt.m_bFindAsYouType)
  78. {
  79. CWnd *pWnd = GetParent();
  80. if(pWnd)
  81. {
  82. pWnd->SendMessage(CB_UPDOWN, pMsg->wParam, pMsg->lParam);
  83. return TRUE;
  84. }
  85. }
  86. // if(!m_bShowingDropDown)
  87. // {
  88. // ShowDropDown();
  89. // return TRUE;
  90. // }
  91. }
  92. else if(pMsg->wParam == 'C' &&
  93. GetKeyState(VK_CONTROL) & 0x8000 ||
  94. pMsg->wParam == 'X' &&
  95. GetKeyState(VK_CONTROL) & 0x8000 ||
  96. pMsg->wParam == VK_DELETE)
  97. {
  98. LONG lEditSel = GetEditSel();
  99. if(LOWORD(lEditSel) == HIWORD(lEditSel))
  100. {
  101. CWnd *pWnd = GetParent();
  102. if(pWnd)
  103. {
  104. pWnd->SendMessage(CB_UPDOWN, pMsg->wParam, pMsg->lParam);
  105. return TRUE;
  106. }
  107. }
  108. }
  109. break;
  110. }
  111. }
  112. return CComboBox::PreTranslateMessage(pMsg);
  113. }