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.

426 lines
12 KiB

  1. #include "common.h"
  2. #include "diskutil.h"
  3. #include "msprintf.h"
  4. #include "drivlist.h"
  5. #include "miniicon.h"
  6. #define cxBITMAP 18
  7. #define cyBITMAP 18
  8. #define cbRESOURCE 256
  9. /*
  10. * VARIABLES __________________________________________________________________
  11. *
  12. */
  13. FARPROC lpfnComboMain;
  14. /*
  15. * PROTOTYPES _________________________________________________________________
  16. *
  17. */
  18. LONG APIENTRY
  19. DriveListProc(
  20. HWND hWnd,
  21. UINT Message,
  22. WPARAM wParam,
  23. LPARAM lParam
  24. );
  25. BOOL CALLBACK
  26. DriveComboProc(
  27. HWND hWnd,
  28. UINT Message,
  29. WPARAM wParam,
  30. LPARAM lParam
  31. );
  32. void
  33. GoSelectDrive(
  34. HWND hWnd,
  35. drenum dre
  36. );
  37. void
  38. DrawDriveItem(
  39. DRAWITEMSTRUCT *lpdi
  40. );
  41. /*
  42. * ROUTINES ___________________________________________________________________
  43. *
  44. */
  45. /*** RegisterDriveList - Registers the DriveList class (always do this!!!)
  46. *
  47. */
  48. BOOL
  49. RegisterDriveList(
  50. HINSTANCE hInst
  51. )
  52. {
  53. WNDCLASS wc;
  54. wc.style = CS_NOCLOSE;
  55. wc.lpfnWndProc = DriveListProc; // Standard callback function
  56. wc.cbClsExtra = 0; // No per-class extra data
  57. wc.cbWndExtra = 12; // We store proc addresses here
  58. wc.hInstance = hInst; // Registering application
  59. wc.hIcon = NULL;
  60. wc.hCursor = LoadCursor (NULL, MAKEINTRESOURCE(IDC_ARROW));
  61. wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
  62. wc.lpszMenuName = NULL; // Name of menu resource in .RC file
  63. wc.lpszClassName = szDriveListCLASS; // Name used in call to CreateWindow
  64. RegisterClass(&wc);
  65. return TRUE;
  66. }
  67. /*** ExitDriveList - Frees memory allocated for the DriveList class
  68. *
  69. */
  70. void
  71. ExitDriveList(
  72. void
  73. )
  74. {
  75. }
  76. /*** DriveListProc - Procedure for handing a DriveList
  77. *
  78. */
  79. LONG APIENTRY
  80. DriveListProc(
  81. HWND hWnd,
  82. UINT Message,
  83. WPARAM wParam,
  84. LPARAM lParam
  85. )
  86. {
  87. MEASUREITEMSTRUCT *lpmi;
  88. CREATESTRUCT *lpcs;
  89. HWND hCombo;
  90. PAINTSTRUCT ps;
  91. long l;
  92. RECT r;
  93. switch (Message)
  94. {
  95. case WM_CREATE:
  96. lpcs = (CREATESTRUCT *)lParam;
  97. if (lpcs->style & STYLE_LISTBOX)
  98. {
  99. MiDebugMsg((0, "CreateWindowEx(ListBox)"));
  100. hCombo = CreateWindowEx (
  101. //EDGE_SUNKEN | WS_EX_EDGEMASK,
  102. EDGE_SUNKEN,
  103. "ListBox",
  104. "",
  105. LBS_OWNERDRAWFIXED | LBS_HASSTRINGS |
  106. WS_VSCROLL |
  107. WS_VISIBLE | WS_CHILD | CBS_SIMPLE,
  108. 0,
  109. 0,
  110. lpcs->cx,
  111. lpcs->cy *5,
  112. hWnd,
  113. NULL,
  114. lpcs->hInstance,
  115. NULL
  116. );
  117. }
  118. else
  119. {
  120. MiDebugMsg((0, "CreateWindowEx(ComboBox)"));
  121. hCombo = CreateWindow (
  122. "ComboBox",
  123. "",
  124. LBS_USETABSTOPS |
  125. CBS_OWNERDRAWFIXED | CBS_HASSTRINGS |
  126. CBS_DROPDOWNLIST | WS_VSCROLL |
  127. WS_VISIBLE | WS_CHILD | CBS_SIMPLE,
  128. 0,
  129. 0,
  130. lpcs->cx,
  131. lpcs->cy *4, // NUMBER LINES in DROP DOWN
  132. hWnd,
  133. NULL,
  134. lpcs->hInstance,
  135. NULL
  136. );
  137. }
  138. SetWindowLong(hWnd, DL_COMBOWND, (long)hCombo);
  139. SetWindowLong(hWnd, DL_UPDATES, 0L);
  140. if (hCombo == NULL)
  141. return -1;
  142. //
  143. //Subclass the combobox
  144. //
  145. lpfnComboMain = (FARPROC)GetWindowLong(hCombo, GWL_WNDPROC);
  146. SetWindowLong(hCombo, GWL_WNDPROC, (LONG)DriveComboProc);
  147. //wproc = (WNDPROC)GetWindowLong (hCombo, GWL_WNDPROC);
  148. //SetWindowLong(hWnd, DL_COMBOPROC, (long)wproc);
  149. //wproc = (WNDPROC)DriveComboProc;
  150. //SetWindowLong(hCombo, GWL_WNDPROC, (long)wproc);
  151. return 0;
  152. break;
  153. case WM_DESTROY:
  154. hCombo = (HWND)GetWindowLong(hWnd, DL_COMBOWND);
  155. if (hCombo != NULL)
  156. {
  157. SetWindowLong (hCombo, GWL_WNDPROC, (long)lpfnComboMain);
  158. DestroyWindow(hCombo);
  159. SetWindowLong(hWnd, DL_COMBOWND, 0L);
  160. }
  161. return 0;
  162. break;
  163. case WM_HELP:
  164. ((LPHELPINFO) lParam)->hItemHandle = hWnd;
  165. return DefWindowProc (hWnd, Message, wParam, lParam);
  166. case WM_CONTEXTMENU:
  167. return DefWindowProc (hWnd, Message, (WPARAM) hWnd, lParam);
  168. case WM_PAINT:
  169. BeginPaint (hWnd, &ps);
  170. EndPaint (hWnd, &ps);
  171. break;
  172. case WM_COMMAND:
  173. if ((HIWORD(lParam) == CBN_SELCHANGE) ||
  174. (HIWORD(lParam) == LBN_SELCHANGE))
  175. {
  176. wParam = GetWindowLong(hWnd, GWL_ID);
  177. SendMessage(GetParent(hWnd),Message,wParam,lParam);
  178. }
  179. break;
  180. case WM_MEASUREITEM:
  181. lpmi = (MEASUREITEMSTRUCT *)lParam;
  182. lpmi->itemWidth = cxBITMAP;
  183. lpmi->itemHeight = cyBITMAP +2;
  184. break;
  185. case WM_DRAWITEM:
  186. DrawDriveItem((DRAWITEMSTRUCT *)lParam);
  187. return 0;
  188. break;
  189. case DL_UPDATESBAD:
  190. l = GetWindowLong(hWnd, DL_UPDATES);
  191. SetWindowLong(hWnd, DL_UPDATES, l+1);
  192. break;
  193. case DL_UPDATESOKAY:
  194. l = GetWindowLong(hWnd, DL_UPDATES);
  195. SetWindowLong(hWnd, DL_UPDATES, l-1);
  196. if (l == 1)
  197. {
  198. GetClientRect(hWnd, &r);
  199. InvalidateRect(hWnd, &r, FALSE);
  200. UpdateWindow(hWnd);
  201. }
  202. break;
  203. }
  204. /*
  205. if ((hCombo = (HWND)GetWindowLong(hWnd, DL_COMBOWND)) == NULL)
  206. return -1;
  207. if ((wproc = (WNDPROC)GetWindowLong(hCombo, GWL_WNDPROC)) == NULL)
  208. return -1;
  209. if (Message > WM_USER)
  210. {
  211. return CallWindowProc(wproc, hCombo, Message, wParam, lParam);
  212. }
  213. if (Message == WM_SETFONT || Message == WM_SETFOCUS || Message == WM_KILLFOCUS)
  214. {
  215. CallWindowProc(wproc, hCombo, Message, wParam, lParam);
  216. }
  217. if (Message == WM_GETDLGCODE)
  218. return (DLGC_WANTCHARS | DLGC_WANTARROWS);
  219. if (Message == WM_KEYDOWN)
  220. {
  221. if ((wParam == VK_UP) || (wParam == VK_DOWN) ||
  222. (wParam == VK_LEFT) || (wParam == VK_RIGHT) ||
  223. (wParam == VK_HOME) || (wParam == VK_END) ||
  224. (wParam == VK_F4))
  225. {
  226. CallWindowProc (wproc, hCombo, Message, wParam, lParam);
  227. Message = WM_CHAR;
  228. }
  229. }
  230. if (Message == WM_CHAR)
  231. {
  232. return CallWindowProc (wproc, hCombo, Message, wParam, lParam);
  233. }
  234. */
  235. return DefWindowProc (hWnd, Message, wParam, lParam);
  236. }
  237. /*** DriveComboProc - Procedure for handing a DriveList
  238. *
  239. */
  240. BOOL CALLBACK
  241. DriveComboProc(
  242. HWND hCombo,
  243. UINT Message,
  244. WPARAM wParam,
  245. LPARAM lParam
  246. )
  247. {
  248. HWND hWnd;
  249. if ((hWnd = GetParent(hCombo)) == NULL)
  250. return -1;
  251. if (Message == WM_GETDLGCODE)
  252. return (DLGC_WANTCHARS | DLGC_WANTARROWS);
  253. if (Message == WM_CHAR)
  254. {
  255. if (wParam >= 'A' && wParam <= 'Z') GoSelectDrive(hWnd, (drenum)(wParam-'A'));
  256. if (wParam >= 'a' && wParam <= 'z') GoSelectDrive(hWnd, (drenum)(wParam-'a'));
  257. return DefWindowProc (hWnd, Message, wParam, lParam);
  258. }
  259. return CallWindowProc((WNDPROC)lpfnComboMain, hCombo, Message, wParam, lParam);
  260. }
  261. /*** GoSelectDrive - Choose a new drive, based on a keypress
  262. *
  263. */
  264. void
  265. GoSelectDrive(
  266. HWND hWnd,
  267. drenum dre
  268. )
  269. {
  270. HWND hCombo;
  271. USHORT nItems;
  272. USHORT n;
  273. DWORD data;
  274. WPARAM wParam;
  275. LPARAM lParam;
  276. BOOL fList;
  277. if ((hCombo = (HWND)GetWindowLong(hWnd, DL_COMBOWND)) == NULL)
  278. return;
  279. fList = (GetWindowLong (hWnd, GWL_STYLE) & STYLE_LISTBOX) ? TRUE : FALSE;
  280. if (fList)
  281. nItems = (USHORT)CallWindowProc((WNDPROC)lpfnComboMain, hCombo, LB_GETCOUNT, 0, 0L);
  282. else
  283. nItems = (USHORT)CallWindowProc((WNDPROC)lpfnComboMain, hCombo, CB_GETCOUNT, 0, 0L);
  284. for (n = 0; n < nItems; n++)
  285. {
  286. if (fList)
  287. data = CallWindowProc ((WNDPROC)lpfnComboMain, hCombo, LB_GETITEMDATA, (WPARAM)n, 0L);
  288. else
  289. data = CallWindowProc ((WNDPROC)lpfnComboMain, hCombo, CB_GETITEMDATA, (WPARAM)n, 0L);
  290. if (LOBYTE(data) == dre)
  291. {
  292. if (fList)
  293. CallWindowProc ((WNDPROC)lpfnComboMain, hCombo, LB_SETCURSEL, (WPARAM)n, 0L);
  294. else
  295. CallWindowProc ((WNDPROC)lpfnComboMain, hCombo, CB_SETCURSEL, (WPARAM)n, 0L);
  296. wParam = (WPARAM)GetWindowLong(hWnd, GWL_ID);
  297. lParam = (LPARAM)MAKELONG((WORD)hCombo, (WORD)CBN_SELCHANGE);
  298. SendMessage(GetParent(hWnd), WM_COMMAND, wParam, lParam);
  299. return;
  300. }
  301. }
  302. MessageBeep (MB_ICONEXCLAMATION);
  303. }
  304. void
  305. DrawDriveItem(
  306. DRAWITEMSTRUCT *lpdi
  307. )
  308. {
  309. TCHAR buf[cbRESOURCE] = "";
  310. HWND hWnd;
  311. int x, y;
  312. HICON hi;
  313. COLORREF clrBk, clrFg;
  314. HBRUSH hb;
  315. int dre;
  316. long l;
  317. if (lpdi->itemAction & ODA_FOCUS)
  318. return;
  319. dre = (int)LOBYTE(lpdi->itemData);
  320. MiDebugMsg((0, "DrawDriveItem for dre %d", dre));
  321. if ((dre != Drive_INV) && ((dre < (int)Drive_A) || (dre > (int)Drive_Z)))
  322. return;
  323. hWnd = GetParent (lpdi->hwndItem);
  324. if (GetWindowLong (hWnd, DL_UPDATES) != 0)
  325. return;
  326. l = GetWindowLong (hWnd, GWL_STYLE);
  327. if (l & STYLE_LISTBOX)
  328. SendMessage (hWnd, LB_GETTEXT, (WPARAM)lpdi->itemID,(LPARAM)(LPTSTR)buf);
  329. else
  330. SendMessage (hWnd, CB_GETLBTEXT,(WPARAM)lpdi->itemID,(LPARAM)(LPTSTR)buf);
  331. x = lpdi->rcItem.left;
  332. y = lpdi->rcItem.top;
  333. hi = GetDriveIcon((drenum)dre);
  334. if (lpdi->itemState & ODS_SELECTED)
  335. {
  336. clrBk = SetBkColor (lpdi->hDC, GetSysColor(COLOR_HIGHLIGHT));
  337. clrFg = SetTextColor (lpdi->hDC, GetSysColor(COLOR_HIGHLIGHTTEXT));
  338. }
  339. else
  340. {
  341. clrBk = SetBkColor (lpdi->hDC, GetSysColor(COLOR_WINDOW));
  342. clrFg = SetTextColor (lpdi->hDC, GetSysColor(COLOR_WINDOWTEXT));
  343. }
  344. hb = CreateSolidBrush (GetBkColor(lpdi->hDC));
  345. FillRect (lpdi->hDC, &lpdi->rcItem, hb);
  346. DeleteObject (hb);
  347. TabbedTextOut (lpdi->hDC, x +((hi == NULL) ? 1 : 21), y+3,
  348. buf, _fstrlen(buf), 0, NULL, 0);
  349. SetBkColor (lpdi->hDC, clrBk);
  350. SetTextColor (lpdi->hDC, clrFg);
  351. if (hi == NULL)
  352. return;
  353. DrawIconEx(lpdi->hDC, x+1, y+1, hi,
  354. MINIY, MINIX, 0, NULL, DI_NORMAL);
  355. }