Leaked source code of windows server 2003
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.

257 lines
6.8 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. TCHAR szTemp[MAX_PATH];
  45. MultiByteToWideChar(CP_ACP, 0, lpwd->PropPrg.achIconFile, -1, szTemp, ARRAYSIZE(szTemp));
  46. TraceMsg(TF_ERROR, "%s", szTemp);
  47. }
  48. #endif // DEBUG
  49. cIcons = (int)ExtractIconExA(lpwd->PropPrg.achIconFile, 0, rgIcons, NULL, MAX_ICONS);
  50. for (iTempIcon = 0; iTempIcon < cIcons; iTempIcon++)
  51. {
  52. ListBox_AddString(hLB, rgIcons[iTempIcon]);
  53. }
  54. ListBox_SetCurSel(hLB, 0);
  55. SendMessage(hLB, WM_SETREDRAW, TRUE, 0L);
  56. InvalidateRect(hLB, NULL, TRUE);
  57. SetCursor(hcurOld);
  58. }
  59. //
  60. //
  61. //
  62. void PickIconInitDlg(HWND hDlg, LPARAM lParam)
  63. {
  64. LPPROPSHEETPAGE lpp = (LPPROPSHEETPAGE)lParam;
  65. LPWIZDATA lpwd = InitWizSheet(hDlg, lParam, 0);
  66. PutIconsInList(GetDlgItem(hDlg, IDC_ICONLIST), lpwd);
  67. }
  68. //
  69. // Returns TRUE if a vaild icon is selected.
  70. //
  71. BOOL PickIconNextPressed(LPWIZDATA lpwd)
  72. {
  73. int iIconIndex = ListBox_GetCurSel(GetDlgItem(lpwd->hwnd, IDC_ICONLIST));
  74. lpwd->PropPrg.wIconIndex = (WORD)iIconIndex;
  75. return(iIconIndex != LB_ERR);
  76. }
  77. //
  78. //
  79. //
  80. BOOL_PTR CALLBACK PickIconDlgProc(HWND hDlg, UINT message , WPARAM wParam, LPARAM lParam)
  81. {
  82. NMHDR FAR *lpnm = NULL;
  83. LPPROPSHEETPAGE lpp = (LPPROPSHEETPAGE)(GetWindowLongPtr(hDlg, DWLP_USER));
  84. LPWIZDATA lpwd = lpp ? (LPWIZDATA)lpp->lParam : NULL;
  85. switch(message)
  86. {
  87. case WM_NOTIFY:
  88. lpnm = (NMHDR FAR *)lParam;
  89. if(lpnm)
  90. {
  91. switch(lpnm->code)
  92. {
  93. case PSN_SETACTIVE:
  94. if(lpwd)
  95. {
  96. //
  97. // If PIFMGR has assigned an icon for this app then
  98. // we'll skip it. This condition only happens when
  99. // creating a shortcut to a single MS-DOS session.
  100. //
  101. if (lpwd->dwFlags & WDFLAG_APPKNOWN)
  102. {
  103. SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  104. }
  105. else
  106. {
  107. lpwd->hwnd = hDlg;
  108. PropSheet_SetWizButtons(GetParent(hDlg),
  109. PSWIZB_BACK | PSWIZB_FINISH);
  110. }
  111. }
  112. break;
  113. case PSN_WIZNEXT:
  114. if(lpwd)
  115. {
  116. if (!PickIconNextPressed(lpwd))
  117. {
  118. SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  119. }
  120. }
  121. break;
  122. case PSN_WIZFINISH:
  123. if(lpwd)
  124. {
  125. if (!(PickIconNextPressed(lpwd) && CreateLink(lpwd)))
  126. {
  127. SetDlgMsgResult(hDlg, WM_NOTIFY, -1);
  128. }
  129. }
  130. break;
  131. case PSN_RESET:
  132. if(lpwd)
  133. {
  134. CleanUpWizData(lpwd);
  135. }
  136. break;
  137. default:
  138. return FALSE;
  139. }
  140. }
  141. break;
  142. case WM_INITDIALOG:
  143. PickIconInitDlg(hDlg, lParam);
  144. break;
  145. case WM_COMMAND:
  146. if(lpwd)
  147. {
  148. if ((GET_WM_COMMAND_ID(wParam, lParam) == IDC_ICONLIST) &&
  149. ((GET_WM_COMMAND_CMD(wParam, lParam) == LBN_DBLCLK)))
  150. {
  151. PropSheet_PressButton(GetParent(hDlg), PSBTN_FINISH);
  152. }
  153. }
  154. break;
  155. //
  156. // owner draw messages for icon listbox
  157. //
  158. case WM_DRAWITEM:
  159. #define lpdi ((DRAWITEMSTRUCT FAR *)lParam)
  160. if (lpdi->itemState & ODS_SELECTED)
  161. SetBkColor(lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
  162. else
  163. SetBkColor(lpdi->hDC, GetSysColor(COLOR_WINDOW));
  164. //
  165. // repaint the selection state
  166. //
  167. ExtTextOut(lpdi->hDC, 0, 0, ETO_OPAQUE, &lpdi->rcItem, NULL, 0, NULL);
  168. //
  169. // draw the icon
  170. //
  171. if ((int)lpdi->itemID >= 0)
  172. DrawIcon(lpdi->hDC, (lpdi->rcItem.left + lpdi->rcItem.right - g_cxIcon) / 2,
  173. (lpdi->rcItem.bottom + lpdi->rcItem.top - g_cyIcon) / 2, (HICON)lpdi->itemData);
  174. // InflateRect(&lpdi->rcItem, -1, -1);
  175. //
  176. // if it has the focus, draw the focus
  177. //
  178. if (lpdi->itemState & ODS_FOCUS)
  179. DrawFocusRect(lpdi->hDC, &lpdi->rcItem);
  180. #undef lpdi
  181. break;
  182. case WM_MEASUREITEM:
  183. #define lpmi ((MEASUREITEMSTRUCT FAR *)lParam)
  184. lpmi->itemWidth = g_cxIcon + 12;
  185. lpmi->itemHeight = g_cyIcon + 4;
  186. #undef lpmi
  187. break;
  188. case WM_DELETEITEM:
  189. #define lpdi ((DELETEITEMSTRUCT FAR *)lParam)
  190. DestroyIcon((HICON)lpdi->itemData);
  191. #undef lpdi
  192. break;
  193. default:
  194. return FALSE;
  195. }
  196. return TRUE;
  197. }