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.

921 lines
36 KiB

  1. /*++
  2. Copyright (c) 1996-2002 Microsoft Corp. & Ricoh Co., Ltd. All rights reserved.
  3. FILE: RIAFUI.CPP
  4. Abstract: Main file for OEM UI plugin module.
  5. Functions: OEMDocumentPropertySheets
  6. OEMCommonUIProp
  7. Environment: Windows NT Unidrv5 driver
  8. Revision History:
  9. 02/25/2000 -Masatoshi Kubokura-
  10. Began to modify for PCL5e/PScript plugin from RPDL code.
  11. 03/31/2000 -Masatoshi Kubokura-
  12. SetWindowLong -> SetWindowLongPtr for 64bit build.
  13. 06/07/2000 -Masatoshi Kubokura-
  14. V.1.11
  15. 08/02/2000 -Masatoshi Kubokura-
  16. V.1.11 for NT4
  17. 11/29/2000 -Masatoshi Kubokura-
  18. Last modified for XP inbox.
  19. 02/26/2002 -Masatoshi Kubokura-
  20. Include strsafe.h.
  21. Add FileNameBufSize as arg3 at RWFileData().
  22. Use OemToCharBuff() instead of OemToChar().
  23. 03/29/2002 -Masatoshi Kubokura-
  24. Eliminate "#if 0".
  25. Use SecureZeroMemory() instead of memset(,0,)
  26. 04/03/2002 -Masatoshi Kubokura-
  27. Use safe_strlenW() instead of lstrlen().
  28. --*/
  29. #include <minidrv.h>
  30. #include "devmode.h"
  31. #include "oem.h"
  32. #include "resource.h"
  33. #include <prsht.h>
  34. #include <mbstring.h> // _ismbcdigit, _ismbcalnum
  35. #ifndef WINNT_40
  36. #include "strsafe.h" // @Feb/26/2002
  37. #endif // !WINNT_40
  38. ////////////////////////////////////////////////////////
  39. // GLOBALS
  40. ////////////////////////////////////////////////////////
  41. HINSTANCE ghInstance = NULL;
  42. ////////////////////////////////////////////////////////
  43. // INTERNAL MACROS and DEFINES
  44. ////////////////////////////////////////////////////////
  45. // @Apr/04/2002 ->
  46. #define RES_ID_MASK 0xffff
  47. #define is_valid_ptr(p) (~RES_ID_MASK & (UINT_PTR)(p))
  48. // @Apr/04/2002 <-
  49. extern "C" {
  50. ////////////////////////////////////////////////////////
  51. // EXTERNAL PROTOTYPES
  52. ////////////////////////////////////////////////////////
  53. extern BOOL RWFileData(PFILEDATA pFileData, LPWSTR pwszFileName, LONG FileNameBufSize, LONG type);
  54. ////////////////////////////////////////////////////////
  55. // INTERNAL PROTOTYPES
  56. ////////////////////////////////////////////////////////
  57. INT_PTR CALLBACK JobPageProc(HWND, UINT, WPARAM, LPARAM);
  58. //////////////////////////////////////////////////////////////////////////
  59. // Function: safe_strlenW
  60. //////////////////////////////////////////////////////////////////////////
  61. INT safe_strlenW(wchar_t* psz, size_t cchMax)
  62. {
  63. #ifndef WINNT_40
  64. HRESULT hr;
  65. size_t cch = 0;
  66. hr = StringCchLengthW(psz, cchMax, &cch);
  67. VERBOSE(("** safe_strlenW: size(lstrlen)=%d **\n", lstrlen(psz)));
  68. VERBOSE(("** safe_strlenW: size(StringCchLength)=%d **\n", cch));
  69. if (SUCCEEDED(hr))
  70. return cch;
  71. else
  72. return 0;
  73. #else // WINNT_40
  74. return lstrlenW(psz);
  75. #endif // WINNT_40
  76. } //*** safe_strlenW
  77. //////////////////////////////////////////////////////////////////////////
  78. // Function: DllMain
  79. //////////////////////////////////////////////////////////////////////////
  80. BOOL WINAPI DllMain(HINSTANCE hInst, WORD wReason, LPVOID lpReserved)
  81. {
  82. #if DBG
  83. //giDebugLevel = DBG_VERBOSE;
  84. ////#define giDebugLevel DBG_VERBOSE // enable VERBOSE() in each file
  85. #endif // DBG
  86. VERBOSE((DLLTEXT("** enter DllMain **\n")));
  87. switch(wReason)
  88. {
  89. case DLL_PROCESS_ATTACH:
  90. VERBOSE((DLLTEXT("** Process attach. **\n")));
  91. // Save DLL instance for use later.
  92. ghInstance = hInst;
  93. break;
  94. case DLL_THREAD_ATTACH:
  95. VERBOSE((DLLTEXT("Thread attach.\n")));
  96. break;
  97. case DLL_PROCESS_DETACH:
  98. VERBOSE((DLLTEXT("Process detach.\n")));
  99. break;
  100. case DLL_THREAD_DETACH:
  101. VERBOSE((DLLTEXT("Thread detach.\n")));
  102. break;
  103. }
  104. return TRUE;
  105. } //*** DllMain
  106. //////////////////////////////////////////////////////////////////////////
  107. // Function: OEMDocumentPropertySheets
  108. //////////////////////////////////////////////////////////////////////////
  109. LRESULT APIENTRY OEMDocumentPropertySheets(PPROPSHEETUI_INFO pPSUIInfo, LPARAM lParam)
  110. {
  111. LRESULT lResult = FALSE;
  112. #if DBG
  113. giDebugLevel = DBG_VERBOSE;
  114. #endif // DBG
  115. // Validate parameters.
  116. if( (NULL == pPSUIInfo)
  117. ||
  118. IsBadWritePtr(pPSUIInfo, pPSUIInfo->cbSize)
  119. ||
  120. (PROPSHEETUI_INFO_VERSION != pPSUIInfo->Version)
  121. ||
  122. ( (PROPSHEETUI_REASON_INIT != pPSUIInfo->Reason)
  123. &&
  124. (PROPSHEETUI_REASON_GET_INFO_HEADER != pPSUIInfo->Reason)
  125. &&
  126. (PROPSHEETUI_REASON_GET_ICON != pPSUIInfo->Reason)
  127. &&
  128. (PROPSHEETUI_REASON_SET_RESULT != pPSUIInfo->Reason)
  129. &&
  130. (PROPSHEETUI_REASON_DESTROY != pPSUIInfo->Reason)
  131. )
  132. )
  133. {
  134. ERR((DLLTEXT("OEMDocumentPropertySheets() ERROR_INVALID_PARAMETER.\n")));
  135. // Return invalid parameter error.
  136. SetLastError(ERROR_INVALID_PARAMETER);
  137. return FALSE;
  138. }
  139. VERBOSE(("\n"));
  140. VERBOSE((DLLTEXT("OEMDocumentPropertySheets() entry. Reason=%d\n"), pPSUIInfo->Reason));
  141. // @Aug/29/2000 ->
  142. #ifdef DISKLESSMODEL
  143. {
  144. DWORD dwError, dwType, dwNeeded;
  145. BYTE ValueData;
  146. POEMUIPSPARAM pOEMUIPSParam = (POEMUIPSPARAM)pPSUIInfo->lParamInit;
  147. dwError = GetPrinterData(pOEMUIPSParam->hPrinter, REG_HARDDISK_INSTALLED, &dwType,
  148. (PBYTE)&ValueData, sizeof(BYTE), &dwNeeded);
  149. if (ERROR_SUCCESS != dwError)
  150. {
  151. VERBOSE((DLLTEXT(" CAN'T READ REGISTRY (%d).\n"), dwError));
  152. return FALSE;
  153. }
  154. else if (!ValueData)
  155. {
  156. VERBOSE((DLLTEXT(" HARD DISK ISN'T INSTALLED.\n")));
  157. return FALSE;
  158. }
  159. }
  160. #endif // DISKLESSMODEL
  161. // @Aug/29/2000 <-
  162. // Do action.
  163. switch(pPSUIInfo->Reason)
  164. {
  165. case PROPSHEETUI_REASON_INIT:
  166. {
  167. POEMUIPSPARAM pOEMUIPSParam = (POEMUIPSPARAM)pPSUIInfo->lParamInit;
  168. POEMUD_EXTRADATA pOEMExtra = MINIPRIVATE_DM(pOEMUIPSParam);
  169. #ifdef WINNT_40
  170. VERBOSE((DLLTEXT("** dwFlags=%lx **\n"), pOEMUIPSParam->dwFlags));
  171. if (pOEMUIPSParam->dwFlags & DM_NOPERMISSION)
  172. BITSET32(pOEMExtra->fUiOption, UIPLUGIN_NOPERMISSION);
  173. #endif // WINNT_40
  174. pPSUIInfo->UserData = NULL;
  175. if ((pPSUIInfo->UserData = (LPARAM)HeapAlloc(pOEMUIPSParam->hOEMHeap,
  176. HEAP_ZERO_MEMORY,
  177. sizeof(UIDATA))))
  178. {
  179. PROPSHEETPAGE Page;
  180. PUIDATA pUiData = (PUIDATA)pPSUIInfo->UserData;
  181. FILEDATA FileData; // <- pFileData (formerly use MemAllocZ) @2000/03/15
  182. // read PRINT_DONE flag from data file
  183. FileData.fUiOption = 0;
  184. RWFileData(&FileData, pOEMExtra->SharedFileName, sizeof(pOEMExtra->SharedFileName), GENERIC_READ);
  185. // set PRINT_DONE flag
  186. if (BITTEST32(FileData.fUiOption, PRINT_DONE))
  187. BITSET32(pOEMExtra->fUiOption, PRINT_DONE);
  188. VERBOSE((DLLTEXT("** Flag=%lx,File Name=%ls **\n"),
  189. pOEMExtra->fUiOption, pOEMExtra->SharedFileName));
  190. pUiData->hComPropSheet = pPSUIInfo->hComPropSheet;
  191. pUiData->pfnComPropSheet = pPSUIInfo->pfnComPropSheet;
  192. pUiData->pOEMExtra = pOEMExtra;
  193. // Init property page.
  194. // Use SecureZeroMemory @Mar/29/2002 ->
  195. #if defined(WINNT_40) || defined(RICOH_RELEASE)
  196. memset(&Page, 0, sizeof(PROPSHEETPAGE));
  197. #else
  198. SecureZeroMemory(&Page, sizeof(PROPSHEETPAGE));
  199. #endif
  200. // Mar/29/2002 <-
  201. Page.dwSize = sizeof(PROPSHEETPAGE);
  202. Page.dwFlags = PSP_DEFAULT;
  203. Page.hInstance = ghInstance;
  204. Page.pszTemplate = MAKEINTRESOURCE(IDD_JOBMAIN);
  205. Page.pfnDlgProc = JobPageProc;
  206. Page.lParam = (LPARAM)pUiData;
  207. // Add property sheets.
  208. lResult = pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet,
  209. CPSFUNC_ADD_PROPSHEETPAGE,
  210. (LPARAM)&Page, 0);
  211. pUiData->hPropPage = (HANDLE)lResult;
  212. VERBOSE((DLLTEXT("** INIT: lResult=%x **\n"), lResult));
  213. lResult = (lResult > 0)? TRUE : FALSE;
  214. }
  215. }
  216. break;
  217. case PROPSHEETUI_REASON_GET_INFO_HEADER:
  218. lResult = TRUE;
  219. break;
  220. case PROPSHEETUI_REASON_GET_ICON:
  221. // No icon
  222. lResult = 0;
  223. break;
  224. case PROPSHEETUI_REASON_SET_RESULT:
  225. {
  226. PSETRESULT_INFO pInfo = (PSETRESULT_INFO) lParam;
  227. lResult = pInfo->Result;
  228. }
  229. break;
  230. case PROPSHEETUI_REASON_DESTROY:
  231. lResult = TRUE;
  232. if (pPSUIInfo->UserData)
  233. {
  234. POEMUIPSPARAM pOEMUIPSParam = (POEMUIPSPARAM)pPSUIInfo->lParamInit;
  235. HeapFree(pOEMUIPSParam->hOEMHeap, 0, (void*)pPSUIInfo->UserData);
  236. }
  237. break;
  238. }
  239. pPSUIInfo->Result = lResult;
  240. return lResult;
  241. } //*** OEMDocumentPropertySheets
  242. /***************************************************************************
  243. Function Name : InitMainDlg
  244. ***************************************************************************/
  245. VOID InitMainDlg(
  246. HWND hDlg,
  247. PUIDATA pUiData)
  248. {
  249. // initialize edit box
  250. SetDlgItemText(hDlg, IDC_EDIT_JOBMAIN_USERID, pUiData->UserIdBuf);
  251. SendDlgItemMessage(hDlg, IDC_EDIT_JOBMAIN_USERID, EM_LIMITTEXT, USERID_LEN, 0);
  252. SetDlgItemText(hDlg, IDC_EDIT_JOBMAIN_PASSWORD, pUiData->PasswordBuf);
  253. SendDlgItemMessage(hDlg, IDC_EDIT_JOBMAIN_PASSWORD, EM_LIMITTEXT, PASSWORD_LEN, 0);
  254. SetDlgItemText(hDlg, IDC_EDIT_JOBMAIN_USERCODE, pUiData->UserCodeBuf);
  255. SendDlgItemMessage(hDlg, IDC_EDIT_JOBMAIN_USERCODE, EM_LIMITTEXT, USERCODE_LEN, 0);
  256. // initialize radio button
  257. CheckRadioButton(hDlg, IDC_RADIO_JOB_NORMAL, IDC_RADIO_JOB_SECURE, pUiData->JobType);
  258. CheckRadioButton(hDlg, IDC_RADIO_LOG_DISABLED, IDC_RADIO_LOG_ENABLED, pUiData->LogDisabled);
  259. // initialize check box
  260. SendDlgItemMessage(hDlg, IDC_CHECK_JOB_DEFAULT, BM_SETCHECK,
  261. (BITTEST32(pUiData->fUiOption, HOLD_OPTIONS)? 0 : 1), 0);
  262. if (1 <= safe_strlenW(pUiData->UserIdBuf, sizeof(pUiData->UserIdBuf)))
  263. {
  264. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SAMPLE), TRUE);
  265. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SECURE), TRUE);
  266. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_JOB_DEFAULT), TRUE);
  267. }
  268. else
  269. {
  270. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SAMPLE), FALSE);
  271. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SECURE), FALSE);
  272. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_JOB_DEFAULT), FALSE);
  273. }
  274. if (IDC_RADIO_JOB_SECURE == pUiData->JobType)
  275. {
  276. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD), TRUE);
  277. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD2), TRUE);
  278. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_PASSWORD), TRUE);
  279. }
  280. else
  281. {
  282. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD), FALSE);
  283. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD2), FALSE);
  284. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_PASSWORD), FALSE);
  285. }
  286. if (IDC_RADIO_LOG_ENABLED == pUiData->LogDisabled)
  287. {
  288. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE), TRUE);
  289. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE2), TRUE);
  290. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_USERCODE), TRUE);
  291. }
  292. else
  293. {
  294. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE), FALSE);
  295. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE2), FALSE);
  296. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_USERCODE), FALSE);
  297. }
  298. #ifdef WINNT_40
  299. // Disable tab options when user has no permission.
  300. if (BITTEST32(pUiData->fUiOption, UIPLUGIN_NOPERMISSION))
  301. {
  302. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERID), FALSE);
  303. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERID2), FALSE);
  304. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERID3), FALSE);
  305. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_JOB), FALSE);
  306. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD), FALSE);
  307. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD2), FALSE);
  308. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_LOG), FALSE);
  309. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE), FALSE);
  310. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE2), FALSE);
  311. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_USERID), FALSE);
  312. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_PASSWORD), FALSE);
  313. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_USERCODE), FALSE);
  314. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_NORMAL), FALSE);
  315. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SAMPLE), FALSE);
  316. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SECURE), FALSE);
  317. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_LOG_DISABLED), FALSE);
  318. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_LOG_ENABLED), FALSE);
  319. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_JOB_DEFAULT), FALSE);
  320. }
  321. #endif // WINNT_40
  322. } //*** InitMainDlg
  323. /***************************************************************************
  324. Function Name : GetInfoFromOEMPdev
  325. get data from private devmode
  326. ***************************************************************************/
  327. VOID GetInfoFromOEMPdev(PUIDATA pUiData)
  328. {
  329. POEMUD_EXTRADATA pOEMExtra = pUiData->pOEMExtra;
  330. VERBOSE((DLLTEXT("GetInfoFromOEMPdev: print done?(%d)\n"),
  331. BITTEST32(pOEMExtra->fUiOption, PRINT_DONE)));
  332. // if previous printing is finished and hold-options flag isn't valid,
  333. // reset job setting.
  334. if (BITTEST32(pOEMExtra->fUiOption, PRINT_DONE) &&
  335. !BITTEST32(pOEMExtra->fUiOption, HOLD_OPTIONS))
  336. {
  337. pUiData->JobType = IDC_RADIO_JOB_NORMAL;
  338. // Use SecureZeroMemory @Mar/26/2002 (MS), Mar/29/2002 ->
  339. #if defined(WINNT_40) || defined(RICOH_RELEASE)
  340. memset(pUiData->PasswordBuf, 0, sizeof(pUiData->PasswordBuf));
  341. #else
  342. SecureZeroMemory(pUiData->PasswordBuf, sizeof(pUiData->PasswordBuf));
  343. #endif
  344. // @Mar/26/2002, Mar/29/2002 <-
  345. // do not clear PRINT_DONE flag here
  346. }
  347. else
  348. {
  349. pUiData->JobType = pOEMExtra->JobType;
  350. // ascii to unicode
  351. // @Feb/27/2002 ->
  352. // OemToChar((LPSTR)pOEMExtra->PasswordBuf, pUiData->PasswordBuf);
  353. OemToCharBuff((LPSTR)pOEMExtra->PasswordBuf, pUiData->PasswordBuf, PASSWORD_LEN);
  354. // @Feb/27/2002 <-
  355. }
  356. pUiData->fUiOption = pOEMExtra->fUiOption;
  357. pUiData->LogDisabled = pOEMExtra->LogDisabled;
  358. // ascii to unicode
  359. // @Feb/27/2002 ->
  360. // OemToChar((LPSTR)pOEMExtra->UserIdBuf, pUiData->UserIdBuf);
  361. // OemToChar((LPSTR)pOEMExtra->UserCodeBuf, pUiData->UserCodeBuf);
  362. OemToCharBuff((LPSTR)pOEMExtra->UserIdBuf, pUiData->UserIdBuf, USERID_LEN);
  363. OemToCharBuff((LPSTR)pOEMExtra->UserCodeBuf, pUiData->UserCodeBuf, USERCODE_LEN);
  364. // @Feb/27/2002 <-
  365. } //*** GetInfoFromOEMPdev
  366. /***************************************************************************
  367. Function Name : SetInfoToOEMPdev
  368. set data to private devmode
  369. ***************************************************************************/
  370. VOID SetInfoToOEMPdev(PUIDATA pUiData)
  371. {
  372. POEMUD_EXTRADATA pOEMExtra = pUiData->pOEMExtra;
  373. // if only main dialog is changed
  374. if (!BITTEST32(pUiData->fUiOption, JOBLOGDLG_UPDATED))
  375. return;
  376. // unicode to ascii
  377. CharToOem(pUiData->UserIdBuf, (LPSTR)pOEMExtra->UserIdBuf);
  378. CharToOem(pUiData->PasswordBuf, (LPSTR)pOEMExtra->PasswordBuf);
  379. CharToOem(pUiData->UserCodeBuf, (LPSTR)pOEMExtra->UserCodeBuf);
  380. pOEMExtra->fUiOption = pUiData->fUiOption & 0x00FF; // clear local bit
  381. pOEMExtra->JobType = pUiData->JobType;
  382. pOEMExtra->LogDisabled = pUiData->LogDisabled;
  383. #if DBG
  384. //DebugBreak();
  385. #endif // DBG
  386. return;
  387. } //*** SetInfoToOEMPdev
  388. /***************************************************************************
  389. Function Name : JobPageProc
  390. Parameters : HWND hDlg Handle of this Dialog
  391. UINT uMessage
  392. WPARAM wParam
  393. LPARAM lParam
  394. Modify Note : Modify. 03/01/2000 Masatoshi Kubokura
  395. ***************************************************************************/
  396. INT_PTR CALLBACK JobPageProc(
  397. HWND hDlg,
  398. UINT uMessage,
  399. WPARAM wParam,
  400. LPARAM lParam)
  401. {
  402. PUIDATA pUiData;
  403. WORD wOldVal, fModified = FALSE, fError = FALSE;
  404. INT iOldLen, iNewLen, iCnt;
  405. #if DBG
  406. giDebugLevel = DBG_VERBOSE;
  407. #endif // DBG
  408. switch (uMessage)
  409. {
  410. case WM_INITDIALOG:
  411. pUiData = (PUIDATA)((LPPROPSHEETPAGE)lParam)->lParam;
  412. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)pUiData);
  413. // get data from private devmode
  414. GetInfoFromOEMPdev(pUiData);
  415. InitMainDlg(hDlg, pUiData);
  416. BITCLR32(pUiData->fUiOption, JOBLOGDLG_UPDATED);
  417. break;
  418. case WM_COMMAND:
  419. pUiData = (PUIDATA)GetWindowLongPtr(hDlg, DWLP_USER);
  420. switch(LOWORD(wParam))
  421. {
  422. case IDC_EDIT_JOBMAIN_USERID:
  423. iOldLen = safe_strlenW(pUiData->UserIdBuf, sizeof(pUiData->UserIdBuf));
  424. GetDlgItemText(hDlg, IDC_EDIT_JOBMAIN_USERID, pUiData->UserIdBuf,
  425. sizeof(pUiData->UserIdBuf) / sizeof(WCHAR));
  426. iNewLen = safe_strlenW(pUiData->UserIdBuf, sizeof(pUiData->UserIdBuf));
  427. if (1 <= iNewLen)
  428. {
  429. if (IDC_RADIO_JOB_SECURE == pUiData->JobType)
  430. {
  431. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD), TRUE);
  432. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD2), TRUE);
  433. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_PASSWORD), TRUE);
  434. }
  435. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SAMPLE), TRUE);
  436. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SECURE), TRUE);
  437. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_JOB_DEFAULT), TRUE);
  438. }
  439. // if UserID isn't set, disable Print Job setting.
  440. else
  441. {
  442. CheckRadioButton(hDlg, IDC_RADIO_JOB_NORMAL, IDC_RADIO_JOB_SECURE,
  443. (pUiData->JobType = IDC_RADIO_JOB_NORMAL));
  444. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SAMPLE), FALSE);
  445. EnableWindow(GetDlgItem(hDlg, IDC_RADIO_JOB_SECURE), FALSE);
  446. EnableWindow(GetDlgItem(hDlg, IDC_CHECK_JOB_DEFAULT), FALSE);
  447. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD), FALSE);
  448. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD2), FALSE);
  449. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_PASSWORD), FALSE);
  450. }
  451. if (iOldLen != iNewLen)
  452. fModified = TRUE;
  453. break;
  454. case IDC_EDIT_JOBMAIN_PASSWORD:
  455. iOldLen = safe_strlenW(pUiData->PasswordBuf, sizeof(pUiData->PasswordBuf));
  456. GetDlgItemText(hDlg, IDC_EDIT_JOBMAIN_PASSWORD, pUiData->PasswordBuf,
  457. sizeof(pUiData->PasswordBuf) / sizeof(WCHAR));
  458. if (iOldLen != safe_strlenW(pUiData->PasswordBuf, sizeof(pUiData->PasswordBuf)))
  459. fModified = TRUE;
  460. break;
  461. case IDC_EDIT_JOBMAIN_USERCODE:
  462. iOldLen = safe_strlenW(pUiData->UserCodeBuf, sizeof(pUiData->UserCodeBuf));
  463. GetDlgItemText(hDlg, IDC_EDIT_JOBMAIN_USERCODE, pUiData->UserCodeBuf,
  464. sizeof(pUiData->UserCodeBuf) / sizeof(WCHAR));
  465. if (iOldLen != safe_strlenW(pUiData->UserCodeBuf, sizeof(pUiData->UserCodeBuf)))
  466. fModified = TRUE;
  467. break;
  468. case IDC_RADIO_JOB_NORMAL:
  469. case IDC_RADIO_JOB_SAMPLE:
  470. case IDC_RADIO_JOB_SECURE:
  471. wOldVal = pUiData->JobType;
  472. CheckRadioButton(hDlg, IDC_RADIO_JOB_NORMAL, IDC_RADIO_JOB_SECURE,
  473. (pUiData->JobType = LOWORD(wParam)));
  474. if (IDC_RADIO_JOB_SECURE == pUiData->JobType)
  475. {
  476. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD), TRUE);
  477. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD2), TRUE);
  478. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_PASSWORD), TRUE);
  479. }
  480. else
  481. {
  482. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD), FALSE);
  483. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_PASSWORD2), FALSE);
  484. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_PASSWORD), FALSE);
  485. }
  486. if (wOldVal != pUiData->JobType)
  487. fModified = TRUE;
  488. break;
  489. case IDC_RADIO_LOG_DISABLED:
  490. case IDC_RADIO_LOG_ENABLED:
  491. wOldVal = pUiData->LogDisabled;
  492. CheckRadioButton(hDlg, IDC_RADIO_LOG_DISABLED, IDC_RADIO_LOG_ENABLED,
  493. (pUiData->LogDisabled = LOWORD(wParam)));
  494. if (IDC_RADIO_LOG_ENABLED == pUiData->LogDisabled)
  495. {
  496. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE), TRUE);
  497. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE2), TRUE);
  498. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_USERCODE), TRUE);
  499. }
  500. else
  501. {
  502. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE), FALSE);
  503. EnableWindow(GetDlgItem(hDlg, IDC_LABEL_JOBMAIN_USERCODE2), FALSE);
  504. EnableWindow(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_USERCODE), FALSE);
  505. }
  506. if (wOldVal != pUiData->LogDisabled)
  507. fModified = TRUE;
  508. break;
  509. case IDC_CHECK_JOB_DEFAULT:
  510. if (BITTEST32(pUiData->fUiOption, HOLD_OPTIONS))
  511. BITCLR32(pUiData->fUiOption, HOLD_OPTIONS);
  512. else
  513. BITSET32(pUiData->fUiOption, HOLD_OPTIONS);
  514. SendDlgItemMessage(hDlg, IDC_CHECK_JOB_DEFAULT, BM_SETCHECK,
  515. (BITTEST32(pUiData->fUiOption, HOLD_OPTIONS)? 0 : 1), 0);
  516. fModified = TRUE;
  517. break;
  518. default:
  519. return FALSE;
  520. }
  521. break;
  522. case WM_NOTIFY:
  523. pUiData = (PUIDATA)GetWindowLongPtr(hDlg, DWLP_USER);
  524. {
  525. NMHDR FAR *lpnmhdr = (NMHDR FAR *)lParam;
  526. switch (lpnmhdr->code)
  527. {
  528. case PSN_SETACTIVE:
  529. break;
  530. // In case of PSN_KILLACTIVE, return FALSE to get PSN_APPLY.
  531. case PSN_KILLACTIVE: // this is when user pushs OK/APPLY button.(1)
  532. VERBOSE((DLLTEXT("** JobPageProc: PSN_KILLACTIVE **\n")));
  533. BITSET32(pUiData->fUiOption, JOBLOGDLG_UPDATED);
  534. // Check User ID (Up to 8 alphanumeric characters)
  535. iNewLen = safe_strlenW(pUiData->UserIdBuf, sizeof(pUiData->UserIdBuf));
  536. for (iCnt = 0; iCnt < iNewLen; iCnt++)
  537. {
  538. // SBCS alphanumeric?
  539. if (!_ismbcalnum(pUiData->UserIdBuf[iCnt]))
  540. {
  541. fError = TRUE;
  542. break;
  543. }
  544. }
  545. if (fError)
  546. {
  547. WCHAR wcTmp1[64], wcTmp2[64];
  548. // set cursor to User ID edit box
  549. SetFocus(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_USERID));
  550. // Display warning dialog
  551. // yasho's point-out @Nov/29/2000 ->
  552. // LoadString(ghInstance, IDS_ERR_USERID_MSG, wcTmp1, sizeof(wcTmp1));
  553. // LoadString(ghInstance, IDS_ERR_USERID_TITLE, wcTmp2, sizeof(wcTmp1));
  554. LoadString(ghInstance, IDS_ERR_USERID_MSG, wcTmp1, sizeof(wcTmp1) / sizeof(*wcTmp1));
  555. LoadString(ghInstance, IDS_ERR_USERID_TITLE, wcTmp2, sizeof(wcTmp2) / sizeof(*wcTmp2));
  556. // @Nov/29/2000 <-
  557. MessageBox(hDlg, wcTmp1, wcTmp2, MB_ICONEXCLAMATION|MB_OK);
  558. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  559. // Do not close property sheets
  560. return TRUE;
  561. }
  562. // Check Password (4 digits)
  563. iNewLen = safe_strlenW(pUiData->PasswordBuf, sizeof(pUiData->PasswordBuf));
  564. if (PASSWORD_LEN != iNewLen) // Password must be exactly 4 digits.
  565. {
  566. fError = TRUE;
  567. }
  568. else
  569. {
  570. for (iCnt = 0; iCnt < iNewLen; iCnt++)
  571. {
  572. // SBCS digit?
  573. if (!_ismbcdigit(pUiData->PasswordBuf[iCnt]))
  574. {
  575. fError = TRUE;
  576. break;
  577. }
  578. }
  579. }
  580. if (fError)
  581. {
  582. // if Secure Print is enabled
  583. if (IDC_RADIO_JOB_SECURE == pUiData->JobType)
  584. {
  585. WCHAR wcTmp1[64], wcTmp2[64];
  586. // set cursor to Password edit box
  587. SetFocus(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_PASSWORD));
  588. // Display warning dialog
  589. LoadString(ghInstance, IDS_ERR_PASSWORD_MSG, wcTmp1, sizeof(wcTmp1) / sizeof(*wcTmp1));
  590. LoadString(ghInstance, IDS_ERR_PASSWORD_TITLE, wcTmp2, sizeof(wcTmp2) / sizeof(*wcTmp2));
  591. MessageBox(hDlg, wcTmp1, wcTmp2, MB_ICONEXCLAMATION|MB_OK);
  592. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  593. // Do not close property sheets
  594. return TRUE;
  595. }
  596. else
  597. {
  598. // Clear invalid Password
  599. // Use SecureZeroMemory @Mar/26/2002 (MS), Mar/29/2002 ->
  600. #if defined(WINNT_40) || defined(RICOH_RELEASE)
  601. memset(pUiData->PasswordBuf, 0, sizeof(pUiData->PasswordBuf));
  602. #else
  603. SecureZeroMemory(pUiData->PasswordBuf, sizeof(pUiData->PasswordBuf));
  604. #endif
  605. // @Mar/26/2002, Mar/29/2002 <-
  606. }
  607. fError = FALSE;
  608. }
  609. // Check User Code (Up to 8 characters)
  610. iNewLen = safe_strlenW(pUiData->UserCodeBuf, sizeof(pUiData->UserCodeBuf));
  611. for (iCnt = 0; iCnt < iNewLen; iCnt++)
  612. {
  613. // SBCS digit?
  614. if (!_ismbcdigit(pUiData->UserCodeBuf[iCnt]))
  615. {
  616. fError = TRUE;
  617. break;
  618. }
  619. }
  620. if (fError)
  621. {
  622. // if Log is enabled
  623. if (IDC_RADIO_LOG_ENABLED == pUiData->LogDisabled)
  624. {
  625. WCHAR wcTmp1[64], wcTmp2[64];
  626. // set cursor to User Code edit box
  627. SetFocus(GetDlgItem(hDlg, IDC_EDIT_JOBMAIN_USERCODE));
  628. // Display warning dialog
  629. LoadString(ghInstance, IDS_ERR_USERCODE_MSG, wcTmp1, sizeof(wcTmp1) / sizeof(*wcTmp1));
  630. LoadString(ghInstance, IDS_ERR_USERCODE_TITLE, wcTmp2, sizeof(wcTmp2) / sizeof(*wcTmp2));
  631. MessageBox(hDlg, wcTmp1, wcTmp2, MB_ICONEXCLAMATION|MB_OK);
  632. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  633. // Do not close property sheets
  634. return TRUE;
  635. }
  636. else
  637. {
  638. // Clear invalid User Code
  639. // Use SecureZeroMemory @Mar/29/2002 ->
  640. #if defined(WINNT_40) || defined(RICOH_RELEASE)
  641. memset(pUiData->UserCodeBuf, 0, sizeof(pUiData->UserCodeBuf));
  642. #else
  643. SecureZeroMemory(pUiData->UserCodeBuf, sizeof(pUiData->UserCodeBuf));
  644. #endif
  645. // Mar/29/2002 <-
  646. }
  647. fError = FALSE;
  648. }
  649. return FALSE;
  650. case PSN_APPLY: // this is when user pushs OK/APPLY button.(2)
  651. VERBOSE((DLLTEXT("** JobPageProc: PSN_APPLY **\n")));
  652. // clear PRINT_DONE flag and delete file.
  653. // BUGBUG: When printing document twice, printing job settings are cleared on app's print dialog
  654. // in 2nd printing. @Sep/05/2000 ->
  655. // if (BITTEST32(pUiData->pOEMExtra->fUiOption, PRINT_DONE))
  656. // {
  657. // BITCLR32(pUiData->pOEMExtra->fUiOption, PRINT_DONE);
  658. // VERBOSE(("** Delete file: %ls **\n", pUiData->pOEMExtra->SharedFileName));
  659. // DeleteFile(pUiData->pOEMExtra->SharedFileName);
  660. // }
  661. if (BITTEST32(pUiData->fUiOption, PRINT_DONE))
  662. {
  663. BITCLR32(pUiData->fUiOption, PRINT_DONE);
  664. VERBOSE(("** Delete file: %ls **\n", pUiData->pOEMExtra->SharedFileName));
  665. DeleteFile(pUiData->pOEMExtra->SharedFileName);
  666. }
  667. // @Sep/05/2000 <-
  668. // set data to private devmode
  669. SetInfoToOEMPdev(pUiData);
  670. // update private devmode
  671. pUiData->pfnComPropSheet(pUiData->hComPropSheet,
  672. CPSFUNC_SET_RESULT,
  673. (LPARAM)pUiData->hPropPage,
  674. (LPARAM)CPSUI_OK);
  675. VERBOSE((DLLTEXT("** PSN_APPLY fUiOption=%x **\n"), pUiData->fUiOption));
  676. break;
  677. case PSN_RESET: // this is when user pushs CANCEL button
  678. VERBOSE((DLLTEXT("** JobPageProc: PSN_RESET **\n")));
  679. break;
  680. }
  681. }
  682. break;
  683. default:
  684. return FALSE;
  685. }
  686. // activate APPLY button
  687. if (fModified)
  688. PropSheet_Changed(GetParent(hDlg), hDlg);
  689. return TRUE;
  690. } //*** JobPageProc
  691. } // End of extern "C"
  692. // @Aug/29/2000 ->
  693. #ifdef DISKLESSMODEL
  694. LONG APIENTRY OEMUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam)
  695. {
  696. LONG Action = CPSUICB_ACTION_NONE;
  697. #if DBG
  698. giDebugLevel = DBG_VERBOSE;
  699. VERBOSE((DLLTEXT("OEMUICallBack() entry.\n")));
  700. #endif // DBG
  701. switch (pCallbackParam->Reason)
  702. {
  703. case CPSUICB_REASON_APPLYNOW:
  704. Action = CPSUICB_ACTION_ITEMS_APPLIED;
  705. {
  706. POPTITEM pOptItem;
  707. WCHAR wcHDName[128];
  708. INT iCnt2;
  709. INT iCnt = ITEM_HARDDISK_NAMES;
  710. INT cOptItem = (INT)pOEMUIParam->cDrvOptItems;
  711. UINT uID = IDS_ITEM_HARDDISK;
  712. BYTE ValueData = 0; // We suppose Hard Disk isn't installed as default.
  713. // Check item name with several candidate ("Hard Disk", "Memory / Hard Disk",...).
  714. while (iCnt-- > 0)
  715. {
  716. LoadString(ghInstance, uID, wcHDName, sizeof(wcHDName) / sizeof(*wcHDName));
  717. uID++;
  718. pOptItem = pOEMUIParam->pDrvOptItems;
  719. for (iCnt2 = 0; iCnt2 < cOptItem; iCnt2++, pOptItem++)
  720. {
  721. // @Apr/04/2002 ->
  722. // if (lstrlen(pOptItem->pName))
  723. if (is_valid_ptr(pOptItem->pName) && safe_strlenW(pOptItem->pName, 128))
  724. // @Apr/04/2002 <-
  725. {
  726. VERBOSE((DLLTEXT("%d: %ls\n"), iCnt2, pOptItem->pName));
  727. // Is item name same as "Hard Disk" or something like?
  728. if (!lstrcmp(pOptItem->pName, wcHDName))
  729. {
  730. // if Hard Disk is installed, value will be 1
  731. ValueData = (BYTE)(pOptItem->Sel % 2);
  732. goto _CHECKNAME_FINISH;
  733. }
  734. }
  735. }
  736. }
  737. _CHECKNAME_FINISH:
  738. // Because pOEMUIParam->pOEMDM (pointer to private devmode) is NULL when
  739. // DrvDevicePropertySheets calls this callback, we use registry.
  740. SetPrinterData(pOEMUIParam->hPrinter, REG_HARDDISK_INSTALLED, REG_BINARY,
  741. (PBYTE)&ValueData, sizeof(BYTE));
  742. }
  743. break;
  744. }
  745. return Action;
  746. } //*** OEMUICallBack
  747. extern "C" {
  748. //////////////////////////////////////////////////////////////////////////
  749. // Function: OEMCommonUIProp
  750. //////////////////////////////////////////////////////////////////////////
  751. BOOL APIENTRY OEMCommonUIProp(DWORD dwMode, POEMCUIPPARAM pOEMUIParam)
  752. {
  753. #if DBG
  754. LPCSTR OEMCommonUIProp_Mode[] = {
  755. "Bad Index",
  756. "OEMCUIP_DOCPROP",
  757. "OEMCUIP_PRNPROP",
  758. };
  759. giDebugLevel = DBG_VERBOSE;
  760. #endif // DBG
  761. if(NULL == pOEMUIParam->pOEMOptItems) // The first call
  762. {
  763. VERBOSE((DLLTEXT("OEMCommonUI(%s) entry 1st.\n"), OEMCommonUIProp_Mode[dwMode]));
  764. if (OEMCUIP_PRNPROP == dwMode)
  765. pOEMUIParam->cOEMOptItems = 1; // dummy item
  766. else
  767. pOEMUIParam->cOEMOptItems = 0;
  768. }
  769. else // The second call
  770. {
  771. VERBOSE((DLLTEXT("OEMCommonUI(%s) entry 2nd.\n"), OEMCommonUIProp_Mode[dwMode]));
  772. if (OEMCUIP_PRNPROP == dwMode) // called from DrvDevicePropertySheets
  773. {
  774. POPTITEM pOptItem = pOEMUIParam->pOEMOptItems;
  775. // fill out data for dummy item
  776. pOptItem->cbSize = sizeof(OPTITEM);
  777. pOptItem->Level = 2; // Level 2
  778. pOptItem->pName = NULL;
  779. pOptItem->pOptType = NULL;
  780. pOptItem->DMPubID = DMPUB_NONE;
  781. pOptItem->Flags = OPTIF_HIDE | OPTIF_CALLBACK; // invisible and with callback
  782. pOEMUIParam->OEMCUIPCallback = OEMUICallBack;
  783. }
  784. #ifdef WINNT_40
  785. else // called from DrvDocumentPropertySheets
  786. {
  787. INT iCnt;
  788. INT cOptItem = (INT)pOEMUIParam->cDrvOptItems;
  789. POPTITEM pOptItem = pOEMUIParam->pDrvOptItems;
  790. // If collate check box exists (i.e. printer collate is available),
  791. // set dmCollate.
  792. // -- Search Copies&Collate item --
  793. for (iCnt = 0; iCnt < cOptItem; iCnt++, pOptItem++)
  794. {
  795. if (DMPUB_COPIES_COLLATE == pOptItem->DMPubID)
  796. {
  797. if (pOptItem->pExtChkBox && pOEMUIParam->pPublicDM)
  798. {
  799. pOEMUIParam->pPublicDM->dmCollate = DMCOLLATE_TRUE;
  800. pOEMUIParam->pPublicDM->dmFields |= DM_COLLATE;
  801. }
  802. break;
  803. }
  804. }
  805. }
  806. #endif // WINNT_40
  807. }
  808. return TRUE;
  809. } //*** OEMCommonUIProp
  810. } // End of extern "C"
  811. #endif // DISKLESSMODEL
  812. // @Aug/29/2000 <-