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.

266 lines
6.9 KiB

  1. //
  2. // PickIcon.C
  3. //
  4. // Copyright (C) Microsoft, 1994,1995 All Rights Reserved.
  5. //
  6. // History:
  7. // ral 6/23/94 - First pass
  8. // 3/20/95 [stevecat] - NT port & real clean up, unicode, etc.
  9. //
  10. //
  11. #include "priv.h"
  12. #include "appwiz.h"
  13. //
  14. // Size?
  15. //
  16. #define MAX_ICONS 75
  17. //
  18. // Adds icons to the list box.
  19. //
  20. void PutIconsInList(HWND hLB, LPWIZDATA lpwd)
  21. {
  22. HICON rgIcons[MAX_ICONS];
  23. int iTempIcon;
  24. int cIcons;
  25. HCURSOR hcurOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
  26. RECT rc;
  27. int cy;
  28. ListBox_SetColumnWidth(hLB, g_cxIcon+12);
  29. //
  30. // compute the height of the listbox based on icon dimensions
  31. //
  32. GetWindowRect(hLB, &rc);
  33. cy = g_cyIcon + GetSystemMetrics(SM_CYHSCROLL) + GetSystemMetrics(SM_CYEDGE) * 3;
  34. SetWindowPos(hLB, NULL, 0, 0, rc.right-rc.left, rc.bottom-rc.top,
  35. SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  36. ListBox_ResetContent(hLB);
  37. SendMessage(hLB, WM_SETREDRAW, FALSE, 0L);
  38. #ifdef DEBUG
  39. {
  40. //
  41. // This is necessary for Unicode (i.e. NT) builds because the shell32
  42. // library does not support ShellMessageBoxA and W versions.
  43. //
  44. #ifdef UNICODE
  45. TCHAR szTemp[MAX_PATH];
  46. MultiByteToWideChar(CP_ACP, 0, lpwd->PropPrg.achIconFile, -1, szTemp, ARRAYSIZE(szTemp));
  47. TraceMsg(TF_ERROR, "%s", szTemp);
  48. #else
  49. TraceMsg(TF_ERROR, "%s", lpwd->PropPrg.achIconFile);
  50. #endif
  51. }
  52. #endif // DEBUG
  53. cIcons = (int)ExtractIconExA(lpwd->PropPrg.achIconFile, 0, rgIcons, NULL, MAX_ICONS);
  54. for (iTempIcon = 0; iTempIcon < cIcons; iTempIcon++)
  55. {
  56. ListBox_AddString(hLB, rgIcons[iTempIcon]);
  57. }
  58. ListBox_SetCurSel(hLB, 0);
  59. SendMessage(hLB, WM_SETREDRAW, TRUE, 0L);
  60. InvalidateRect(hLB, NULL, TRUE);
  61. SetCursor(hcurOld);
  62. }
  63. //
  64. //
  65. //
  66. void PickIconInitDlg(HWND hDlg, LPARAM lParam)
  67. {
  68. LPPROPSHEETPAGE lpp = (LPPROPSHEETPAGE)lParam;
  69. LPWIZDATA lpwd = InitWizSheet(hDlg, lParam, 0);
  70. PutIconsInList(GetDlgItem(hDlg, IDC_ICONLIST), lpwd);
  71. }
  72. //
  73. // Returns TRUE if a vaild icon is selected.
  74. //
  75. BOOL PickIconNextPressed(LPWIZDATA lpwd)
  76. {
  77. int iIconIndex = ListBox_GetCurSel(GetDlgItem(lpwd->hwnd, IDC_ICONLIST));
  78. lpwd->PropPrg.wIconIndex = (WORD)iIconIndex;
  79. return(iIconIndex != LB_ERR);
  80. }
  81. //
  82. //
  83. //
  84. BOOL_PTR CALLBACK PickIconDlgProc(HWND hDlg, UINT message , WPARAM wParam, LPARAM lParam)
  85. {
  86. NMHDR FAR *lpnm = NULL;
  87. LPPROPSHEETPAGE lpp = (LPPROPSHEETPAGE)(GetWindowLongPtr(hDlg, DWLP_USER));
  88. LPWIZDATA lpwd = lpp ? (LPWIZDATA)lpp->lParam : NULL;
  89. switch(message)
  90. {
  91. case WM_NOTIFY:
  92. lpnm = (NMHDR FAR *)lParam;
  93. if(lpnm)
  94. {
  95. switch(lpnm->code)
  96. {
  97. case PSN_SETACTIVE:
  98. if(lpwd)
  99. {
  100. //
  101. // If PIFMGR has assigned an icon for this app then
  102. // we'll skip it. This condition only happens when
  103. // creating a shortcut to a single MS-DOS session.
  104. //
  105. if (lpwd->dwFlags & WDFLAG_APPKNOWN)
  106. {
  107. SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  108. }
  109. else
  110. {
  111. lpwd->hwnd = hDlg;
  112. PropSheet_SetWizButtons(GetParent(hDlg),
  113. (lpwd->dwFlags & WDFLAG_SINGLEAPP) ?
  114. PSWIZB_BACK | PSWIZB_NEXT :
  115. PSWIZB_BACK | PSWIZB_FINISH);
  116. }
  117. }
  118. break;
  119. case PSN_WIZNEXT:
  120. if(lpwd)
  121. {
  122. if (!PickIconNextPressed(lpwd))
  123. {
  124. SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  125. }
  126. }
  127. break;
  128. case PSN_WIZFINISH:
  129. if(lpwd)
  130. {
  131. if (!(PickIconNextPressed(lpwd) && CreateLink(lpwd)))
  132. {
  133. SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  134. }
  135. }
  136. break;
  137. case PSN_RESET:
  138. if(lpwd)
  139. {
  140. CleanUpWizData(lpwd);
  141. }
  142. break;
  143. default:
  144. return FALSE;
  145. }
  146. }
  147. break;
  148. case WM_INITDIALOG:
  149. PickIconInitDlg(hDlg, lParam);
  150. break;
  151. case WM_COMMAND:
  152. if(lpwd)
  153. {
  154. if ((GET_WM_COMMAND_ID(wParam, lParam) == IDC_ICONLIST) &&
  155. ((GET_WM_COMMAND_CMD(wParam, lParam) == LBN_DBLCLK)))
  156. {
  157. PropSheet_PressButton(GetParent(hDlg),
  158. (lpwd->dwFlags & WDFLAG_SINGLEAPP) ?
  159. PSBTN_NEXT : PSBTN_FINISH);
  160. }
  161. }
  162. break;
  163. //
  164. // owner draw messages for icon listbox
  165. //
  166. case WM_DRAWITEM:
  167. #define lpdi ((DRAWITEMSTRUCT FAR *)lParam)
  168. if (lpdi->itemState & ODS_SELECTED)
  169. SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
  170. else
  171. SetBkColor(lpdi->hDC, GetSysColor(COLOR_WINDOW));
  172. //
  173. // repaint the selection state
  174. //
  175. ExtTextOut(lpdi->hDC, 0, 0, ETO_OPAQUE, &lpdi->rcItem, NULL, 0, NULL);
  176. //
  177. // draw the icon
  178. //
  179. if ((int)lpdi->itemID >= 0)
  180. DrawIcon(lpdi->hDC, (lpdi->rcItem.left + lpdi->rcItem.right - g_cxIcon) / 2,
  181. (lpdi->rcItem.bottom + lpdi->rcItem.top - g_cyIcon) / 2, (HICON)lpdi->itemData);
  182. // InflateRect(&lpdi->rcItem, -1, -1);
  183. //
  184. // if it has the focus, draw the focus
  185. //
  186. if (lpdi->itemState & ODS_FOCUS)
  187. DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
  188. #undef lpdi
  189. break;
  190. case WM_MEASUREITEM:
  191. #define lpmi ((MEASUREITEMSTRUCT FAR *)lParam)
  192. lpmi->itemWidth = g_cxIcon + 12;
  193. lpmi->itemHeight = g_cyIcon + 4;
  194. #undef lpmi
  195. break;
  196. case WM_DELETEITEM:
  197. #define lpdi ((DELETEITEMSTRUCT FAR *)lParam)
  198. DestroyIcon((HICON)lpdi->itemData);
  199. #undef lpdi
  200. break;
  201. default:
  202. return FALSE;
  203. }
  204. return TRUE;
  205. }