Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1999 - 1999
  6. //
  7. // File: ccomboex.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. // CComboex.cpp
  11. #include "stdafx.h"
  12. #include "ccomboex.h"
  13. BOOL CComboBoxEx2::FindItem(COMBOBOXEXITEM* pComboItem, int nStart)
  14. {
  15. ASSERT(pComboItem != NULL);
  16. ASSERT(nStart >= -1);
  17. // Only suport lparam search for now
  18. ASSERT(pComboItem->mask == CBEIF_LPARAM);
  19. int nItems = GetCount();
  20. COMBOBOXEXITEM ComboItem;
  21. ComboItem.mask = CBEIF_LPARAM;
  22. for (int iItem = nStart+1; iItem < nItems; iItem++)
  23. {
  24. ComboItem.iItem = iItem;
  25. BOOL bStat = GetItem(&ComboItem);
  26. ASSERT(bStat);
  27. if (ComboItem.lParam == pComboItem->lParam)
  28. return iItem;
  29. }
  30. return -1;
  31. }
  32. //+-------------------------------------------------------
  33. //
  34. // FindNextBranch(iItem)
  35. //
  36. // This function returns the index of the next item which
  37. // is not within the branch rooted at iItem. If no next
  38. // branch is found, the fucntion returns the item count.
  39. //+-------------------------------------------------------
  40. int CComboBoxEx2::FindNextBranch(int iItem)
  41. {
  42. int nItems = GetCount();
  43. ASSERT(iItem >= 0 && iItem < nItems);
  44. COMBOBOXEXITEM ComboItem;
  45. ComboItem.mask = CBEIF_INDENT;
  46. // Get indent of start item
  47. ComboItem.iItem = iItem;
  48. BOOL bStat = GetItem(&ComboItem);
  49. ASSERT(bStat);
  50. int iIndent = ComboItem.iIndent;
  51. // Locate next item with LE indent
  52. while (++iItem < nItems)
  53. {
  54. ComboItem.iItem = iItem;
  55. BOOL bStat = GetItem(&ComboItem);
  56. ASSERT(bStat);
  57. if (ComboItem.iIndent <= iIndent)
  58. return iItem;
  59. }
  60. return nItems;
  61. }
  62. //+------------------------------------------------------
  63. //
  64. // DeleteBranch
  65. //
  66. // This function deletes the item as the specified index
  67. // and all children of the item.
  68. //+------------------------------------------------------
  69. void CComboBoxEx2::DeleteBranch(int iItem)
  70. {
  71. int iNextBranch = FindNextBranch(iItem);
  72. for (int i=iItem; i< iNextBranch; i++)
  73. {
  74. DeleteItem(iItem);
  75. }
  76. }
  77. //+------------------------------------------------------
  78. //
  79. // FixUp
  80. //
  81. // This function is a workaround for two bugs in the NT4
  82. // version of comctl32.dll. First it turns off the
  83. // nointegralheight style of the inner combo box, which
  84. // the comboxex code forces on during creation. Next it
  85. // adjusts the size of the outer comboboxex wnd to be the
  86. // same size as the inner combobox wnd. Without this the
  87. // outer box cuts off the bottom of the inner box.
  88. //+------------------------------------------------------
  89. void CComboBoxEx2::FixUp()
  90. {
  91. ASSERT(::IsWindow(m_hWnd));
  92. HWND hWndCombo = GetComboControl();
  93. ASSERT(::IsWindow(hWndCombo));
  94. ::SetWindowLong( hWndCombo, GWL_STYLE, ::GetWindowLong( hWndCombo, GWL_STYLE ) & ~CBS_NOINTEGRALHEIGHT );
  95. RECT rc;
  96. ::GetWindowRect(hWndCombo,&rc);
  97. SetWindowPos(NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOZORDER);
  98. }