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.

163 lines
4.0 KiB

  1. /*****************************************************************************
  2. *
  3. * diqchk.c
  4. *
  5. * Wrappers that turn a listview into a checked listbox.
  6. *
  7. *****************************************************************************/
  8. #include "diquick.h"
  9. HIMAGELIST g_himlState;
  10. #pragma BEGIN_CONST_DATA
  11. /*****************************************************************************
  12. *
  13. * Checklist_Init
  14. *
  15. * One-time initialization.
  16. *
  17. *****************************************************************************/
  18. INT_PTR EXTERNAL
  19. Checklist_Init(void)
  20. {
  21. g_himlState = ImageList_LoadImage(g_hinst, MAKEINTRESOURCE(IDB_CHECK),
  22. 0, 2, RGB(0xFF, 0x00, 0xFF),
  23. IMAGE_BITMAP, 0);
  24. return (INT_PTR)g_himlState;
  25. }
  26. /*****************************************************************************
  27. *
  28. * Checklist_Term
  29. *
  30. * One-time shutdown
  31. *
  32. *****************************************************************************/
  33. void EXTERNAL
  34. Checklist_Term(void)
  35. {
  36. if (g_himlState) {
  37. ImageList_Destroy(g_himlState);
  38. }
  39. }
  40. /*****************************************************************************
  41. *
  42. * Checklist_OnInitDialog
  43. *
  44. * Initialize a single checklist control.
  45. *
  46. *****************************************************************************/
  47. void EXTERNAL
  48. Checklist_OnInitDialog(HWND hwnd, BOOL fReadOnly)
  49. {
  50. ListView_SetImageList(hwnd, g_himlState, LVSIL_STATE);
  51. if (fReadOnly) {
  52. SetProp(hwnd, propReadOnly, LongToHandle((LONG)fReadOnly) );
  53. ListView_SetBkColor(hwnd, GetSysColor(COLOR_3DFACE));
  54. ListView_SetTextBkColor(hwnd, GetSysColor(COLOR_3DFACE));
  55. }
  56. }
  57. /*****************************************************************************
  58. *
  59. * Checklist_AddString
  60. *
  61. * Add a string and maybe a checkbox.
  62. *
  63. *****************************************************************************/
  64. int EXTERNAL
  65. Checklist_AddString(HWND hwnd, UINT ids, BOOL fCheck)
  66. {
  67. TCHAR tsz[256];
  68. LV_ITEM lvi;
  69. LoadString(g_hinst, ids, tsz, cA(tsz));
  70. lvi.mask = LVIF_TEXT | LVIF_STATE;
  71. lvi.iSubItem = 0;
  72. lvi.pszText = tsz;
  73. lvi.state = INDEXTOSTATEIMAGEMASK(fCheck ? 2 : 1);
  74. lvi.stateMask = LVIS_STATEIMAGEMASK;
  75. lvi.iItem = ListView_GetItemCount(hwnd);
  76. return ListView_InsertItem(hwnd, &lvi);
  77. }
  78. /*****************************************************************************
  79. *
  80. * Checklist_InitFinish
  81. *
  82. * Wind up the initialization.
  83. *
  84. *****************************************************************************/
  85. void EXTERNAL
  86. Checklist_InitFinish(HWND hwnd)
  87. {
  88. RECT rc;
  89. LV_COLUMN col;
  90. int icol;
  91. /*
  92. * Add the one and only column.
  93. */
  94. GetClientRect(hwnd, &rc);
  95. col.mask = LVCF_WIDTH;
  96. col.cx = 10;
  97. icol = ListView_InsertColumn(hwnd, 0, &col);
  98. ListView_SetColumnWidth(hwnd, icol, LVSCW_AUTOSIZE);
  99. }
  100. /*****************************************************************************
  101. *
  102. * Checklist_OnDestroy
  103. *
  104. * Clean up a checklist.
  105. *
  106. *****************************************************************************/
  107. void EXTERNAL
  108. Checklist_OnDestroy(HWND hwnd)
  109. {
  110. /*
  111. * Don't remove unless it's already there.
  112. * This avoids a RIP.
  113. */
  114. if (GetProp(hwnd, propReadOnly)) {
  115. RemoveProp(hwnd, propReadOnly);
  116. }
  117. }
  118. /*****************************************************************************
  119. *
  120. * Checklist_InitFlags
  121. *
  122. * Add a bunch of strings corresponding to flag bits.
  123. *
  124. *****************************************************************************/
  125. void EXTERNAL
  126. Checklist_InitFlags(HWND hdlg, int idc,
  127. DWORD fl, PCHECKLISTFLAG rgclf, UINT cclf)
  128. {
  129. HWND hwndList = GetDlgItem(hdlg, idc);
  130. UINT iclf;
  131. Checklist_OnInitDialog(hwndList, TRUE);
  132. for (iclf = 0; iclf < cclf; iclf++) {
  133. Checklist_AddString(hwndList, rgclf[iclf].ids,
  134. fl & rgclf[iclf].flMask);
  135. }
  136. Checklist_InitFinish(hwndList);
  137. }