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.

525 lines
14 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. #include "precomp.h"
  3. #include <commctrl.h>
  4. #include "utils.h"
  5. //#include <assert.h>
  6. extern HINSTANCE g_hInstance;
  7. void SetDeleteKeyStatus(int iValue) ;
  8. int GetDeleteKeyStatus(void) ;
  9. void MoveCaretRetail(int nID, HWND hwnd )
  10. {
  11. POINT Pt;
  12. int iCaretIndex ;
  13. DWORD dwNext = 0;
  14. TCHAR tcUserValue[ CHARS_IN_BATCH + 1];
  15. DWORD dwLen ;
  16. GetCaretPos(&Pt);
  17. iCaretIndex = (int) SendMessage(GetDlgItem(hwnd,nID), EM_CHARFROMPOS, 0, MAKELPARAM(Pt.x, Pt.y));
  18. GetDlgItemText(hwnd,nID, tcUserValue, CHARS_IN_BATCH+1);
  19. dwLen = _tcslen(tcUserValue);
  20. switch(iCaretIndex)
  21. {
  22. case 0: //Move to left edit box
  23. dwNext = -1 ;
  24. switch(nID)
  25. {
  26. case IDC_RETAILSPK2:
  27. dwNext = IDC_RETAILSPK1;
  28. break ;
  29. case IDC_RETAILSPK3:
  30. dwNext = IDC_RETAILSPK2;
  31. break ;
  32. case IDC_RETAILSPK4:
  33. dwNext = IDC_RETAILSPK3;
  34. break ;
  35. case IDC_RETAILSPK5:
  36. dwNext = IDC_RETAILSPK4;
  37. break ;
  38. }
  39. if (dwNext != -1 && dwLen == 0 && GetDeleteKeyStatus() == 0)
  40. {
  41. SetFocus(GetDlgItem(hwnd, dwNext));
  42. SendMessage(GetDlgItem(hwnd,dwNext),WM_KEYDOWN, VK_END,0);
  43. }
  44. break;
  45. case 5: //Move to right edit box
  46. dwNext = -1 ;
  47. switch(nID)
  48. {
  49. case IDC_RETAILSPK1:
  50. dwNext = IDC_RETAILSPK2;
  51. break ;
  52. case IDC_RETAILSPK2:
  53. dwNext = IDC_RETAILSPK3;
  54. break ;
  55. case IDC_RETAILSPK3:
  56. dwNext = IDC_RETAILSPK4;
  57. break ;
  58. case IDC_RETAILSPK4:
  59. dwNext = IDC_RETAILSPK5;
  60. break ;
  61. }
  62. if (dwNext != -1)
  63. {
  64. SetFocus(GetDlgItem(hwnd, dwNext));
  65. SendMessage(GetDlgItem(hwnd,dwNext),WM_KEYDOWN, VK_HOME,0);
  66. }
  67. break;
  68. }
  69. }
  70. LRW_DLG_INT CALLBACK
  71. RetailSPKProc(
  72. IN HWND hwnd,
  73. IN UINT uMsg,
  74. IN WPARAM wParam,
  75. IN LPARAM lParam
  76. )
  77. {
  78. DWORD dwRetCode = ERROR_SUCCESS;
  79. DWORD dwNextPage = 0;
  80. BOOL bStatus = TRUE;
  81. HWND hWndListView = GetDlgItem(hwnd, IDC_RETAILSPKLIST );
  82. HWND hSPKField = GetDlgItem(hwnd, IDC_RETAILSPK1);
  83. PageInfo *pi = (PageInfo *)LRW_GETWINDOWLONG( hwnd, LRW_GWL_USERDATA );
  84. int lo = LOWORD(wParam);
  85. int hi = HIWORD(wParam);
  86. if(hi == 1)
  87. {
  88. int b = 0;
  89. }
  90. switch (uMsg)
  91. {
  92. case WM_INITDIALOG:
  93. pi = (PageInfo *)((LPPROPSHEETPAGE)lParam)->lParam;
  94. LRW_SETWINDOWLONG( hwnd, LRW_GWL_USERDATA, (LRW_LONG_PTR)pi );
  95. SendDlgItemMessage (hwnd, IDC_RETAILSPK1, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  96. SendDlgItemMessage (hwnd, IDC_RETAILSPK2, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  97. SendDlgItemMessage (hwnd, IDC_RETAILSPK3, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  98. SendDlgItemMessage (hwnd, IDC_RETAILSPK4, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  99. SendDlgItemMessage (hwnd, IDC_RETAILSPK5, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  100. //Setup columns in list view
  101. {
  102. LV_COLUMN lvColumn;
  103. TCHAR lpszHeader[ 128];
  104. lvColumn.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  105. lvColumn.fmt = LVCFMT_LEFT;
  106. lvColumn.cx = 225;
  107. LoadString(GetInstanceHandle(), IDS_RETAIL_HEADERSPK, lpszHeader, sizeof(lpszHeader)/sizeof(TCHAR));
  108. lvColumn.pszText = lpszHeader;
  109. ListView_InsertColumn(hWndListView, 0, &lvColumn);
  110. lvColumn.cx = 150;
  111. LoadString(GetInstanceHandle(), IDS_RETAIL_HEADERSTATUS, lpszHeader, sizeof(lpszHeader)/sizeof(TCHAR));
  112. lvColumn.pszText = lpszHeader;
  113. ListView_InsertColumn(hWndListView, 1, &lvColumn);
  114. // Now that this is done, pre-populate the List Control from the Internal
  115. // List, if any
  116. ListView_SetItemCount(hWndListView, MAX_RETAILSPKS_IN_BATCH);
  117. }
  118. break;
  119. case WM_SHOWWINDOW:
  120. if (wParam)
  121. {
  122. // List is being shown
  123. // Clean-it up & Load the list view
  124. ListView_DeleteAllItems(hWndListView);
  125. LoadFromList(hWndListView);
  126. }
  127. break;
  128. case WM_COMMAND:
  129. if (HIWORD(wParam) == EN_CHANGE)
  130. {
  131. MoveCaretRetail(LOWORD(wParam), hwnd ) ;
  132. }
  133. if (HIWORD(wParam) == EN_UPDATE)
  134. {
  135. if (GetKeyState(VK_DELETE) == -128)
  136. SetDeleteKeyStatus(1) ;
  137. else
  138. SetDeleteKeyStatus(0) ;
  139. }
  140. else
  141. {
  142. switch ( LOWORD(wParam) ) //from which control
  143. {
  144. case IDC_ADDBUTTON:
  145. if (HIWORD(wParam) == BN_CLICKED)
  146. {
  147. TCHAR lpVal[ LR_RETAILSPK_LEN+1];
  148. GetDlgItemText(hwnd,IDC_RETAILSPK1, lpVal, CHARS_IN_BATCH+1);
  149. GetDlgItemText(hwnd,IDC_RETAILSPK2, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  150. GetDlgItemText(hwnd,IDC_RETAILSPK3, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  151. GetDlgItemText(hwnd,IDC_RETAILSPK4, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  152. GetDlgItemText(hwnd,IDC_RETAILSPK5, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  153. if ((dwRetCode=AddRetailSPKToList(hWndListView, lpVal)) != ERROR_SUCCESS)
  154. {
  155. // Could not validate the SPK because of SOME reason
  156. LRMessageBox(hwnd,dwRetCode);
  157. if(dwRetCode == IDS_ERR_TOOMANYSPK)
  158. {
  159. // Blank out the field & continue
  160. SetDlgItemText(hwnd, IDC_RETAILSPK1, _TEXT(""));
  161. SetDlgItemText(hwnd, IDC_RETAILSPK2, _TEXT(""));
  162. SetDlgItemText(hwnd, IDC_RETAILSPK3, _TEXT(""));
  163. SetDlgItemText(hwnd, IDC_RETAILSPK4, _TEXT(""));
  164. SetDlgItemText(hwnd, IDC_RETAILSPK5, _TEXT(""));
  165. }
  166. }
  167. else
  168. {
  169. // Blank out the field & continue
  170. SetDlgItemText(hwnd, IDC_RETAILSPK1, _TEXT(""));
  171. SetDlgItemText(hwnd, IDC_RETAILSPK2, _TEXT(""));
  172. SetDlgItemText(hwnd, IDC_RETAILSPK3, _TEXT(""));
  173. SetDlgItemText(hwnd, IDC_RETAILSPK4, _TEXT(""));
  174. SetDlgItemText(hwnd, IDC_RETAILSPK5, _TEXT(""));
  175. }
  176. SetFocus(hSPKField);
  177. }
  178. break;
  179. case IDC_DELETEBUTTON:
  180. if (HIWORD(wParam) == BN_CLICKED)
  181. {
  182. TCHAR lpVal[ LR_RETAILSPK_LEN+1];
  183. int nItem = ListView_GetSelectionMark(hWndListView);
  184. if (nItem != -1)
  185. {
  186. LVITEM lvItem;
  187. lvItem.mask = LVIF_TEXT;
  188. lvItem.iItem = nItem;
  189. lvItem.iSubItem = 0;
  190. lvItem.pszText = lpVal;
  191. lvItem.cchTextMax = LR_RETAILSPK_LEN+1;
  192. ListView_GetItem(hWndListView, &lvItem);
  193. // Something is selected, Delete it
  194. ListView_DeleteItem(hWndListView, nItem);
  195. DeleteRetailSPKFromList(lvItem.pszText);
  196. ListView_SetSelectionMark(hWndListView, -1);
  197. }
  198. SetFocus(hSPKField);
  199. }
  200. break;
  201. case IDC_EDITBUTTON:
  202. if (HIWORD(wParam) == BN_CLICKED)
  203. {
  204. CString sModifiedRetailSPK;
  205. TCHAR lpVal[ LR_RETAILSPK_LEN+1];
  206. int nItem = ListView_GetSelectionMark(hWndListView);
  207. if (nItem != -1 )
  208. {
  209. LVITEM lvItem;
  210. lvItem.mask = LVIF_TEXT;
  211. lvItem.iItem = nItem;
  212. lvItem.iSubItem = 0;
  213. lvItem.pszText = lpVal;
  214. lvItem.cchTextMax = LR_RETAILSPK_LEN+1;
  215. ListView_GetItem(hWndListView, &lvItem);
  216. SetModifiedRetailSPK(lvItem.pszText);
  217. //Show dialog box to Edit the SPK
  218. if ( DialogBox ( GetInstanceHandle(),
  219. MAKEINTRESOURCE(IDD_EDIT_RETAILSPK),
  220. hwnd,
  221. EditRetailSPKDlgProc
  222. ) == IDOK )
  223. {
  224. //Get the modified SPK
  225. GetModifiedRetailSPK(sModifiedRetailSPK);
  226. ModifyRetailSPKFromList(lvItem.pszText,(LPTSTR)(LPCTSTR)sModifiedRetailSPK);
  227. ListView_SetItemText(hWndListView,nItem,0,(LPTSTR)(LPCTSTR)sModifiedRetailSPK);
  228. }
  229. ListView_SetSelectionMark(GetDlgItem(hwnd,IDC_RETAILSPKLIST),-1);
  230. }
  231. SetFocus(hSPKField);
  232. }
  233. }
  234. }
  235. break;
  236. case WM_DESTROY:
  237. LRW_SETWINDOWLONG( hwnd, LRW_GWL_USERDATA, NULL );
  238. break;
  239. case WM_NOTIFY:
  240. {
  241. BOOL bGoNextPage = TRUE ;
  242. LPNMHDR pnmh = (LPNMHDR)lParam;
  243. switch( pnmh->code )
  244. {
  245. case PSN_SETACTIVE:
  246. {
  247. DWORD dwStyle = BS_DEFPUSHBUTTON|BS_CENTER|BS_VCENTER|BS_NOTIFY|WS_GROUP;
  248. SendDlgItemMessage (hwnd, IDC_ADDBUTTON, BM_SETSTYLE,(WPARAM)LOWORD(dwStyle), MAKELPARAM(TRUE, 0));
  249. PropSheet_SetWizButtons( GetParent( hwnd ), PSWIZB_NEXT | PSWIZB_BACK);
  250. }
  251. break;
  252. case PSN_WIZNEXT:
  253. TCHAR lpVal[ LR_RETAILSPK_LEN+1];
  254. DWORD dwRetCode;
  255. if (GetFocus() == GetDlgItem(hwnd,IDC_ADDBUTTON)) //Fix bug #312
  256. {
  257. bGoNextPage = FALSE;
  258. }
  259. // Read the SPK from the Field
  260. GetDlgItemText(hwnd,IDC_RETAILSPK1, lpVal, CHARS_IN_BATCH+1);
  261. GetDlgItemText(hwnd,IDC_RETAILSPK2, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  262. GetDlgItemText(hwnd,IDC_RETAILSPK3, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  263. GetDlgItemText(hwnd,IDC_RETAILSPK4, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  264. GetDlgItemText(hwnd,IDC_RETAILSPK5, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  265. if (lstrlen(lpVal) != 0)
  266. {
  267. dwRetCode = AddRetailSPKToList(hWndListView, lpVal);
  268. if (dwRetCode != IDS_ERR_TOOMANYSPK && dwRetCode != ERROR_SUCCESS)
  269. {
  270. // Could not validate the SPK because of SOME reason
  271. dwNextPage = IDD_DLG_RETAILSPK;
  272. LRMessageBox(hwnd, dwRetCode);
  273. SetFocus(hSPKField);
  274. }
  275. else
  276. {
  277. SetDlgItemText(hwnd, IDC_RETAILSPK1, _TEXT(""));
  278. SetDlgItemText(hwnd, IDC_RETAILSPK2, _TEXT(""));
  279. SetDlgItemText(hwnd, IDC_RETAILSPK3, _TEXT(""));
  280. SetDlgItemText(hwnd, IDC_RETAILSPK4, _TEXT(""));
  281. SetDlgItemText(hwnd, IDC_RETAILSPK5, _TEXT(""));
  282. if (bGoNextPage == FALSE)
  283. {
  284. dwNextPage = IDD_DLG_RETAILSPK;
  285. SetFocus(hSPKField);
  286. }
  287. else
  288. dwNextPage = IDD_PROGRESS;
  289. }
  290. }
  291. else if (ListView_GetItemCount(hWndListView) <= 0)
  292. {
  293. LRMessageBox(hwnd, IDS_NOSPKSTOPROCESS);
  294. dwNextPage = IDD_DLG_RETAILSPK;
  295. }
  296. else
  297. {
  298. dwNextPage = IDD_PROGRESS;
  299. // LRPush(IDD_DLG_RETAILSPK);
  300. }
  301. if (dwNextPage == IDD_PROGRESS)
  302. {
  303. dwRetCode = ShowProgressBox(hwnd, ProcessThread, 0, 0, 0);
  304. LRPush( IDD_DLG_RETAILSPK );
  305. }
  306. LRW_SETWINDOWLONG(hwnd, LRW_DWL_MSGRESULT, dwNextPage);
  307. bStatus = -1;
  308. break;
  309. case PSN_WIZBACK:
  310. dwNextPage = LRPop();
  311. LRW_SETWINDOWLONG(hwnd, LRW_DWL_MSGRESULT, dwNextPage);
  312. bStatus = -1;
  313. break;
  314. case NM_KILLFOCUS:
  315. if(pnmh->idFrom == IDC_RETAILSPKLIST && GetFocus() != GetDlgItem(hwnd,IDC_ADDBUTTON) &&
  316. GetFocus() != GetDlgItem(hwnd,IDC_EDITBUTTON) && GetFocus() != GetDlgItem(hwnd,IDC_DELETEBUTTON))
  317. {
  318. ListView_SetSelectionMark(GetDlgItem(hwnd,IDC_RETAILSPKLIST),-1);
  319. }
  320. break;
  321. default:
  322. bStatus = FALSE;
  323. break;
  324. }
  325. }
  326. break;
  327. default:
  328. bStatus = FALSE;
  329. break;
  330. }
  331. return bStatus;
  332. }
  333. LRW_DLG_INT CALLBACK EditRetailSPKDlgProc( IN HWND hwndDlg, // handle to dialog box
  334. IN UINT uMsg, // message
  335. IN WPARAM wParam, // first message parameter
  336. IN LPARAM lParam // second message parameter
  337. )
  338. {
  339. BOOL bRetCode = FALSE;
  340. TCHAR lpVal[ LR_RETAILSPK_LEN+1];
  341. switch ( uMsg )
  342. {
  343. case WM_INITDIALOG:
  344. {
  345. CString sFullRetailSPK;
  346. CString sSPK1,sSPK2,sSPK3,sSPK4,sSPK5;
  347. int nIndex = 0;
  348. LPTSTR lpVal = NULL;
  349. sFullRetailSPK.Empty();
  350. sSPK1.Empty();
  351. sSPK2.Empty();
  352. sSPK3.Empty();
  353. sSPK4.Empty();
  354. sSPK5.Empty();
  355. GetModifiedRetailSPK(sFullRetailSPK);
  356. sSPK1 = sFullRetailSPK.Mid(nIndex,CHARS_IN_BATCH);
  357. nIndex += CHARS_IN_BATCH;
  358. sSPK2 = sFullRetailSPK.Mid(nIndex,CHARS_IN_BATCH);
  359. nIndex += CHARS_IN_BATCH;
  360. sSPK3 = sFullRetailSPK.Mid(nIndex,CHARS_IN_BATCH);
  361. nIndex += CHARS_IN_BATCH;
  362. sSPK4 = sFullRetailSPK.Mid(nIndex,CHARS_IN_BATCH);
  363. nIndex += CHARS_IN_BATCH;
  364. sSPK5 = sFullRetailSPK.Mid(nIndex,CHARS_IN_BATCH);
  365. SendDlgItemMessage (hwndDlg, IDC_RETAILSPK1, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  366. SendDlgItemMessage (hwndDlg, IDC_RETAILSPK2, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  367. SendDlgItemMessage (hwndDlg, IDC_RETAILSPK3, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  368. SendDlgItemMessage (hwndDlg, IDC_RETAILSPK4, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  369. SendDlgItemMessage (hwndDlg, IDC_RETAILSPK5, EM_SETLIMITTEXT, CHARS_IN_BATCH,0);
  370. SetDlgItemText(hwndDlg, IDC_RETAILSPK1, sSPK1);
  371. SetDlgItemText(hwndDlg, IDC_RETAILSPK2, sSPK2);
  372. SetDlgItemText(hwndDlg, IDC_RETAILSPK3, sSPK3);
  373. SetDlgItemText(hwndDlg, IDC_RETAILSPK4, sSPK4);
  374. SetDlgItemText(hwndDlg, IDC_RETAILSPK5, sSPK5);
  375. bRetCode = TRUE;
  376. }
  377. break;
  378. case WM_COMMAND:
  379. if (HIWORD(wParam) == EN_CHANGE)
  380. {
  381. MoveCaretRetail(LOWORD(wParam), hwndDlg ) ;
  382. }
  383. if (HIWORD(wParam) == EN_UPDATE)
  384. {
  385. if (GetKeyState(VK_DELETE) == -128)
  386. SetDeleteKeyStatus(1) ;
  387. else
  388. SetDeleteKeyStatus(0) ;
  389. }
  390. else
  391. {
  392. switch ( LOWORD(wParam) ) //from which control
  393. {
  394. case IDOK:
  395. if (HIWORD(wParam) == BN_CLICKED)
  396. {
  397. DWORD dwRetCode = ERROR_SUCCESS;
  398. CString sOldRetailSPK;
  399. GetModifiedRetailSPK(sOldRetailSPK);
  400. GetDlgItemText(hwndDlg,IDC_RETAILSPK1, lpVal, CHARS_IN_BATCH+1);
  401. GetDlgItemText(hwndDlg,IDC_RETAILSPK2, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  402. GetDlgItemText(hwndDlg,IDC_RETAILSPK3, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  403. GetDlgItemText(hwndDlg,IDC_RETAILSPK4, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  404. GetDlgItemText(hwndDlg,IDC_RETAILSPK5, lpVal+lstrlen(lpVal), CHARS_IN_BATCH+1);
  405. //Set the new spk only if changed
  406. if(_tcsicmp(sOldRetailSPK,(LPCTSTR)lpVal))
  407. {
  408. dwRetCode = ValidateRetailSPK(lpVal);
  409. if(dwRetCode != ERROR_SUCCESS)
  410. {
  411. LRMessageBox(hwndDlg, dwRetCode);
  412. return TRUE;
  413. }
  414. SetModifiedRetailSPK(lpVal);
  415. }
  416. EndDialog(hwndDlg, IDOK);
  417. bRetCode = TRUE;
  418. }
  419. break;
  420. case IDCANCEL:
  421. if (HIWORD(wParam) == BN_CLICKED)
  422. {
  423. EndDialog(hwndDlg, IDCANCEL);
  424. bRetCode = TRUE;
  425. }
  426. default:
  427. break;
  428. }
  429. }
  430. break;
  431. default:
  432. break;
  433. }
  434. return bRetCode;
  435. }