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.

1062 lines
33 KiB

  1. /******************************************************************************
  2. Source File: AppUI.CPP
  3. This file implements the Application UI. This consists of two (ANSI/UNICODE)
  4. functions that allow an application to specify profiles to be used, and so
  5. forth.
  6. Copyright (c) 1996 by Microsoft Corporation
  7. A Pretty Penny Enterprises Production
  8. Change History:
  9. 12-11-96 a-robkj@microsoft.com Created it
  10. ******************************************************************************/
  11. #include "ICMUI.H"
  12. CONST DWORD ApplicationUIHelpIds[] = {
  13. ApplyButton, IDH_ICMUI_APPLY,
  14. EnableICM, IDH_APPUI_ICM,
  15. EnableBasic, IDH_APPUI_BASIC,
  16. EnableProofing, IDH_APPUI_PROOF,
  17. MonitorProfile, IDH_APPUI_MONITOR,
  18. MonitorProfileLabel, IDH_APPUI_MONITOR,
  19. PrinterProfile, IDH_APPUI_PRINTER,
  20. PrinterProfileLabel, IDH_APPUI_PRINTER,
  21. RenderingIntent, IDH_APPUI_INTENT,
  22. RenderingIntentLabel, IDH_APPUI_INTENT,
  23. TargetProfile, IDH_APPUI_EMULATE,
  24. TargetProfileLabel, IDH_APPUI_EMULATE,
  25. TargetIntent, IDH_APPUI_INTENT,
  26. TargetIntentLabel, IDH_APPUI_INTENT,
  27. #if !defined(_WIN95_) // context-sentitive help
  28. // SourceProfile, IDH_APPUI_SOURCE,
  29. SourceProfileLabel, IDH_APPUI_SOURCE,
  30. #endif
  31. 0, 0
  32. };
  33. class CColorMatchDialog : public CDialog {
  34. BOOL m_bSuccess, m_bEnableICM, m_bEnableProofing, m_bColorPrinter;
  35. CString m_csSource, m_csMonitor, m_csPrinter,
  36. m_csMonitorProfile, m_csPrinterProfile, m_csTargetProfile;
  37. CString m_csMonitorDisplayName; // since displayName != deviceName for monitor.
  38. CStringArray m_csaMonitor, m_csaPrinter, m_csaTarget;
  39. CStringArray m_csaMonitorDesc, m_csaPrinterDesc, m_csaTargetDesc;
  40. // For handy reference (from Setup structure)
  41. DWORD m_dwRenderIntent, m_dwProofIntent;
  42. // To reduce stack usage and code size
  43. HWND m_hwndRenderIntent, m_hwndTargetIntent, m_hwndMonitorList,
  44. m_hwndPrinterList, m_hwndTargetList, m_hwndIntentText1,
  45. m_hwndIntentLabel, m_hwndTargetProfileLabel, m_hwndTargetIntentLabel,
  46. m_hwndMonitorProfileLabel, m_hwndPrinterProfileLabel;
  47. // For Apply callback
  48. PCMSCALLBACK m_dpApplyCallback;
  49. LPARAM m_lpApplyCallback;
  50. // To identify callee
  51. BOOL m_bAnsiCall;
  52. // Display profile description or filename
  53. BOOL m_bUseProfileDescription;
  54. // Intent control
  55. BOOL m_bDisableIntent, m_bDisableRenderIntent;
  56. // Pointer to COLORMATCHSETUP[A|W]
  57. PVOID m_pvCMS;
  58. void Fail(DWORD dwError);
  59. BOOL GoodParms(PCOLORMATCHSETUP pcms);
  60. void CompleteInitialization();
  61. void UpdateControls(BOOL bChanged = FALSE);
  62. void FillStructure(COLORMATCHSETUPA *pcms);
  63. void FillStructure(COLORMATCHSETUPW *pcms);
  64. void EnableApplyButton(BOOL bEnable = TRUE);
  65. public:
  66. CColorMatchDialog(COLORMATCHSETUPA *pcms);
  67. CColorMatchDialog(COLORMATCHSETUPW *pcms);
  68. ~CColorMatchDialog() {
  69. m_csaMonitor.Empty();
  70. m_csaPrinter.Empty();
  71. m_csaTarget.Empty();
  72. m_csaMonitorDesc.Empty();
  73. m_csaPrinterDesc.Empty();
  74. m_csaTargetDesc.Empty();
  75. m_csSource.Empty();
  76. m_csMonitor.Empty();
  77. m_csPrinter.Empty();
  78. m_csMonitorProfile.Empty();
  79. m_csPrinterProfile.Empty();
  80. m_csTargetProfile.Empty();
  81. m_csMonitorDisplayName.Empty();
  82. }
  83. BOOL Results() const { return m_bSuccess; }
  84. virtual BOOL OnInit();
  85. virtual BOOL OnCommand(WORD wNotifyCode, WORD wid, HWND hwndCtl);
  86. virtual BOOL OnHelp(LPHELPINFO pHelp);
  87. virtual BOOL OnContextMenu(HWND hwnd);
  88. };
  89. // Record a failure
  90. void CColorMatchDialog::Fail(DWORD dwError) {
  91. SetLastError(dwError);
  92. m_bSuccess = FALSE;
  93. }
  94. // Report input parameter validity
  95. BOOL CColorMatchDialog::GoodParms(PCOLORMATCHSETUP pcms) {
  96. m_bSuccess = TRUE;
  97. if (!pcms || pcms -> dwVersion != COLOR_MATCH_VERSION ||
  98. pcms -> dwSize != sizeof *pcms || !pcms -> pMonitorProfile ||
  99. !pcms -> pPrinterProfile || !pcms -> pTargetProfile ||
  100. !pcms -> ccMonitorProfile || !pcms -> ccPrinterProfile ||
  101. !pcms -> ccTargetProfile) {
  102. Fail(ERROR_INVALID_PARAMETER);
  103. return FALSE;
  104. }
  105. if (pcms -> dwFlags & CMS_USEHOOK && !pcms -> lpfnHook)
  106. Fail(ERROR_INVALID_PARAMETER);
  107. if (pcms -> dwFlags & CMS_USEAPPLYCALLBACK && !pcms -> lpfnApplyCallback)
  108. Fail(ERROR_INVALID_PARAMETER);
  109. if (pcms -> dwFlags & CMS_SETRENDERINTENT &&
  110. pcms -> dwRenderIntent > INTENT_ABSOLUTE_COLORIMETRIC)
  111. Fail(ERROR_INVALID_PARAMETER);
  112. if (pcms -> dwFlags & CMS_SETPROOFINTENT &&
  113. pcms -> dwFlags & CMS_ENABLEPROOFING &&
  114. pcms -> dwProofingIntent > INTENT_ABSOLUTE_COLORIMETRIC)
  115. Fail(ERROR_INVALID_PARAMETER);
  116. // Setup the hooking, if needed
  117. if (pcms -> dwFlags & CMS_USEHOOK) {
  118. m_dpHook = pcms -> lpfnHook;
  119. m_lpHook = pcms -> lParam;
  120. }
  121. // Setup the callback for apply, if needed
  122. if (pcms -> dwFlags & CMS_USEAPPLYCALLBACK) {
  123. m_dpApplyCallback = pcms -> lpfnApplyCallback;
  124. m_lpApplyCallback = pcms -> lParamApplyCallback;
  125. } else {
  126. m_dpApplyCallback = NULL;
  127. m_lpApplyCallback = 0L;
  128. }
  129. // Cache the flags...
  130. DWORD dwFlags = pcms -> dwFlags;
  131. // Init the intents
  132. m_dwRenderIntent = (dwFlags & CMS_SETRENDERINTENT) ?
  133. pcms -> dwRenderIntent : INTENT_PERCEPTUAL;
  134. m_dwProofIntent = (dwFlags & CMS_SETPROOFINTENT) && (dwFlags & CMS_ENABLEPROOFING) ?
  135. pcms -> dwProofingIntent : m_dwRenderIntent;
  136. // Init the flags
  137. m_bEnableICM = !(dwFlags & CMS_DISABLEICM);
  138. m_bEnableProofing = !!(dwFlags & CMS_ENABLEPROOFING);
  139. m_bUseProfileDescription = !!(dwFlags & CMS_USEDESCRIPTION);
  140. m_bDisableIntent = !!(dwFlags & CMS_DISABLEINTENT);
  141. m_bDisableRenderIntent = !!(dwFlags & CMS_DISABLERENDERINTENT);
  142. // Init the pointer to buffer
  143. m_pvCMS = (PVOID) pcms;
  144. return m_bSuccess;
  145. }
  146. // Encoding-independent construction actions
  147. void CColorMatchDialog::CompleteInitialization() {
  148. // Determine the appropriate source, monitor and printer names
  149. if (m_csSource.IsEmpty())
  150. m_csSource.Load(DefaultSourceString);
  151. // Check the validation for monitor name.
  152. CMonitorList cml;
  153. cml.Enumerate();
  154. if (!cml.IsValidDeviceName(m_csMonitor)) {
  155. // Get primary device.
  156. m_csMonitor = cml.PrimaryDeviceName();
  157. }
  158. // Map display name from device name
  159. m_csMonitorDisplayName = cml.DeviceNameToDisplayName(m_csMonitor);
  160. // Check the validation for printer name.
  161. HANDLE hPrinter;
  162. if (!m_csPrinter.IsEmpty() && OpenPrinter(m_csPrinter,&hPrinter,NULL)) {
  163. // The specified printer has been found.
  164. ClosePrinter(hPrinter);
  165. } else {
  166. // The specified printer has not been found,
  167. // Get the default printer name- do it the old, slimy way...
  168. TCHAR acBuffer[MAX_PATH];
  169. GetProfileString(_TEXT("Windows"), _TEXT("Device"), _TEXT(""),
  170. acBuffer, MAX_PATH);
  171. // The buffer will contains "PrinterName,DriverName,Port".
  172. // What we need is only printer name.
  173. TCHAR *pTmp = acBuffer;
  174. while (*pTmp) {
  175. if (*pTmp == __TEXT(',')) {
  176. *pTmp = NULL;
  177. break;
  178. }
  179. pTmp++;
  180. }
  181. m_csPrinter = acBuffer;
  182. }
  183. if (CGlobals::ThisIsAColorPrinter(m_csPrinter))
  184. m_bColorPrinter = TRUE;
  185. else
  186. m_bColorPrinter = FALSE;
  187. // Now, we collect the names
  188. ENUMTYPE et = { sizeof et, ENUM_TYPE_VERSION, (ET_DEVICENAME|ET_DEVICECLASS) };
  189. // Enumrate monitor.
  190. et.pDeviceName = m_csMonitor;
  191. et.dwDeviceClass = CLASS_MONITOR;
  192. CProfile::Enumerate(et, m_csaMonitor, m_csaMonitorDesc);
  193. // Enumrate only for Color Printer.
  194. if (m_bColorPrinter) {
  195. et.pDeviceName = m_csPrinter;
  196. et.dwDeviceClass = CLASS_PRINTER;
  197. CProfile::Enumerate(et, m_csaPrinter, m_csaPrinterDesc);
  198. } else {
  199. m_csaPrinter.Empty();
  200. m_csaPrinterDesc.Empty();
  201. }
  202. et.dwFields = 0;
  203. CProfile::Enumerate(et, m_csaTarget, m_csaTargetDesc);
  204. // Fix up the default names for the profiles
  205. if (m_csaPrinter.Map(m_csPrinterProfile) == m_csaPrinter.Count())
  206. {
  207. _RPTF2(_CRT_WARN, "Printer Profile %s isn't associated with "
  208. "the monitor (%s)", (LPCTSTR) m_csPrinterProfile,
  209. (LPCTSTR) m_csPrinter);
  210. if (m_csaPrinter.Count())
  211. {
  212. m_csPrinterProfile = m_csaPrinter[0];
  213. }
  214. else
  215. {
  216. m_csPrinterProfile = (LPCTSTR) NULL;
  217. }
  218. }
  219. if (m_csaMonitor.Map(m_csMonitorProfile) == m_csaMonitor.Count())
  220. {
  221. _RPTF2(_CRT_WARN, "Monitor Profile %s isn't associated with "
  222. "the monitor (%s)", (LPCTSTR) m_csMonitorProfile,
  223. (LPCTSTR) m_csMonitor);
  224. if (m_csaMonitor.Count())
  225. {
  226. m_csMonitorProfile = m_csaMonitor[0];
  227. }
  228. else
  229. {
  230. m_csMonitorProfile = (LPCTSTR) NULL;
  231. }
  232. }
  233. // If the target profile name is invalid, use the printer profile
  234. if (m_csaTarget.Map(m_csTargetProfile) == m_csaTarget.Count())
  235. {
  236. _RPTF1(_CRT_WARN, "Target Profile %s isn't installed",
  237. (LPCTSTR) m_csTargetProfile);
  238. if (m_csaPrinter.Count())
  239. {
  240. m_csTargetProfile = m_csaPrinter[0];
  241. }
  242. else
  243. {
  244. // And then, there is no printer profile, it will
  245. // be Windows color space profile.
  246. TCHAR TargetProfileName[MAX_PATH];
  247. DWORD dwSize = MAX_PATH;
  248. if (GetStandardColorSpaceProfile(NULL,LCS_WINDOWS_COLOR_SPACE,TargetProfileName,&dwSize)) {
  249. m_csTargetProfile = (LPCTSTR) TargetProfileName;
  250. m_csTargetProfile = (LPCTSTR) m_csTargetProfile.NameAndExtension();
  251. } else {
  252. m_csTargetProfile = (LPCTSTR) NULL;
  253. }
  254. }
  255. }
  256. }
  257. // Update the controls
  258. void CColorMatchDialog::UpdateControls(BOOL bChanged) {
  259. // Switch Proofing Controls based on setting
  260. ShowWindow(m_hwndIntentText1, m_bEnableProofing && m_bEnableICM ? SW_SHOWNORMAL : SW_HIDE);
  261. EnableWindow(m_hwndTargetProfileLabel, m_bEnableProofing && m_bEnableICM);
  262. EnableWindow(m_hwndTargetList, m_bEnableProofing && m_bEnableICM);
  263. EnableWindow(m_hwndTargetIntentLabel, m_bEnableProofing && m_bEnableICM && !m_bDisableIntent);
  264. EnableWindow(m_hwndTargetIntent, m_bEnableProofing && m_bEnableICM && !m_bDisableIntent);
  265. // Switch the other Controls, as well...
  266. EnableWindow(m_hwndMonitorProfileLabel, m_bEnableICM);
  267. EnableWindow(m_hwndMonitorList, m_bEnableICM);
  268. EnableWindow(m_hwndPrinterProfileLabel, m_bEnableICM && !m_csPrinter.IsEmpty());
  269. EnableWindow(m_hwndPrinterList, m_bEnableICM && m_bColorPrinter && !m_csPrinter.IsEmpty());
  270. if (m_bEnableProofing) {
  271. EnableWindow(m_hwndIntentLabel, m_bEnableICM && !m_bDisableIntent && !m_bDisableRenderIntent);
  272. EnableWindow(m_hwndRenderIntent, m_bEnableICM && !m_bDisableIntent && !m_bDisableRenderIntent);
  273. } else {
  274. EnableWindow(m_hwndIntentLabel, m_bEnableICM && !m_bDisableIntent);
  275. EnableWindow(m_hwndRenderIntent, m_bEnableICM && !m_bDisableIntent);
  276. }
  277. EnableWindow(GetDlgItem(m_hwnd, EnableBasic), m_bEnableICM);
  278. EnableWindow(GetDlgItem(m_hwnd, EnableProofing), m_bEnableICM);
  279. EnableApplyButton(bChanged);
  280. }
  281. // Update the Apply buttom
  282. void CColorMatchDialog::EnableApplyButton(BOOL bEnable) {
  283. EnableWindow(GetDlgItem(m_hwnd, ApplyButton), bEnable);
  284. }
  285. // Flags for buffer overflow (combined)
  286. #define BAD_BUFFER_FLAGS (CMS_MONITOROVERFLOW | CMS_PRINTEROVERFLOW | \
  287. CMS_TARGETOVERFLOW)
  288. // By moving the ANSI / Unicode issues into the CString class
  289. // it becomes feasible to code these two versions so they look
  290. // encoding-independent. In other words, the code for both
  291. // of these versions is written identically, and the compiler
  292. // does all the work, just like it ought to...
  293. void CColorMatchDialog::FillStructure(COLORMATCHSETUPA *pcms) {
  294. if (m_bEnableICM) {
  295. pcms -> dwFlags = CMS_SETRENDERINTENT | CMS_SETPRINTERPROFILE |
  296. CMS_SETMONITORPROFILE;
  297. pcms -> dwRenderIntent = m_dwRenderIntent;
  298. // 03-20-1997 [email protected] RAID 21091 (Memphis)
  299. // Don't fail if there is no monitor or printer profile. Set
  300. // them to an empty string and succeed, instead.
  301. // We can always do this, because 0 counts and empty pointers
  302. // have already been screened out.
  303. if (m_csMonitorProfile.IsEmpty())
  304. pcms -> pMonitorProfile[0] = '\0';
  305. else {
  306. lstrcpynA(pcms -> pMonitorProfile, m_csMonitorProfile,
  307. pcms -> ccMonitorProfile);
  308. if (lstrcmpA(pcms -> pMonitorProfile, m_csMonitorProfile))
  309. pcms -> dwFlags |= CMS_MONITOROVERFLOW;
  310. }
  311. if (m_csPrinterProfile.IsEmpty() || !m_bColorPrinter)
  312. pcms -> pPrinterProfile[0] = '\0';
  313. else {
  314. lstrcpynA(pcms -> pPrinterProfile, m_csPrinterProfile,
  315. pcms -> ccPrinterProfile);
  316. if (lstrcmpA(pcms -> pPrinterProfile, m_csPrinterProfile))
  317. pcms -> dwFlags |= CMS_PRINTEROVERFLOW;
  318. }
  319. if (m_bEnableProofing) {
  320. pcms -> dwFlags |=
  321. CMS_ENABLEPROOFING | CMS_SETTARGETPROFILE;
  322. pcms -> dwProofingIntent = m_dwProofIntent;
  323. lstrcpynA(pcms -> pTargetProfile, m_csTargetProfile,
  324. pcms -> ccTargetProfile);
  325. if (lstrcmpA(pcms -> pTargetProfile, m_csTargetProfile))
  326. pcms -> dwFlags |= CMS_TARGETOVERFLOW;
  327. } else {
  328. pcms -> pTargetProfile[0] = '\0';
  329. }
  330. if (pcms -> dwFlags & BAD_BUFFER_FLAGS)
  331. Fail(ERROR_INSUFFICIENT_BUFFER);
  332. }
  333. else
  334. {
  335. pcms -> dwFlags = CMS_DISABLEICM; // No other flags are valid!
  336. pcms -> pMonitorProfile[0] = '\0'; // No color profiles are choosed
  337. pcms -> pPrinterProfile[0] = '\0';
  338. pcms -> pTargetProfile[0] = '\0';
  339. }
  340. }
  341. void CColorMatchDialog::FillStructure(COLORMATCHSETUPW *pcms) {
  342. if (m_bEnableICM) {
  343. pcms -> dwFlags = CMS_SETRENDERINTENT | CMS_SETPRINTERPROFILE |
  344. CMS_SETMONITORPROFILE;
  345. pcms -> dwRenderIntent = m_dwRenderIntent;
  346. // 03-20-1997 [email protected] RAID 21091 (Memphis)
  347. // Don't fail if there is no monitor or printer profile. Set
  348. // them to an empty string and succeed, instead.
  349. // We can always do this, because 0 counts and empty pointers
  350. // have already been screened out.
  351. if (m_csMonitorProfile.IsEmpty())
  352. pcms -> pMonitorProfile[0] = '\0';
  353. else {
  354. lstrcpynW(pcms -> pMonitorProfile, m_csMonitorProfile,
  355. pcms -> ccMonitorProfile);
  356. if (lstrcmpW(pcms -> pMonitorProfile, m_csMonitorProfile))
  357. pcms -> dwFlags |= CMS_MONITOROVERFLOW;
  358. }
  359. if (m_csPrinterProfile.IsEmpty() || !m_bColorPrinter)
  360. pcms -> pPrinterProfile[0] = '\0';
  361. else {
  362. lstrcpynW(pcms -> pPrinterProfile, m_csPrinterProfile,
  363. pcms -> ccPrinterProfile);
  364. if (lstrcmpW(pcms -> pPrinterProfile, m_csPrinterProfile))
  365. pcms -> dwFlags |= CMS_PRINTEROVERFLOW;
  366. }
  367. if (m_bEnableProofing) {
  368. pcms -> dwFlags |=
  369. CMS_ENABLEPROOFING | CMS_SETTARGETPROFILE | CMS_SETPROOFINTENT;
  370. pcms -> dwProofingIntent = m_dwProofIntent;
  371. lstrcpynW(pcms -> pTargetProfile, m_csTargetProfile,
  372. pcms -> ccTargetProfile);
  373. if (lstrcmpW(pcms -> pTargetProfile, m_csTargetProfile))
  374. pcms -> dwFlags |= CMS_TARGETOVERFLOW;
  375. } else {
  376. pcms -> pTargetProfile[0] = '\0';
  377. }
  378. if (pcms -> dwFlags & BAD_BUFFER_FLAGS)
  379. Fail(ERROR_INSUFFICIENT_BUFFER);
  380. }
  381. else
  382. {
  383. pcms -> dwFlags = CMS_DISABLEICM; // No other flags are valid!
  384. pcms -> pMonitorProfile[0] = '\0'; // No color profiles are choosed
  385. pcms -> pPrinterProfile[0] = '\0';
  386. pcms -> pTargetProfile[0] = '\0';
  387. }
  388. }
  389. CColorMatchDialog::CColorMatchDialog(COLORMATCHSETUPA *pcms) :
  390. CDialog(CGlobals::Instance(), ApplicationUI, pcms -> hwndOwner) {
  391. if (!GoodParms((PCOLORMATCHSETUP) pcms))
  392. return;
  393. // Make sure we've initialized these, if we have to.
  394. if (pcms -> dwFlags & CMS_SETMONITORPROFILE)
  395. m_csMonitorProfile = pcms -> pMonitorProfile;
  396. if (pcms -> dwFlags & CMS_SETPRINTERPROFILE)
  397. m_csPrinterProfile = pcms -> pPrinterProfile;
  398. if (pcms -> dwFlags & CMS_SETTARGETPROFILE)
  399. m_csTargetProfile = pcms -> pTargetProfile;
  400. m_csSource = pcms -> pSourceName;
  401. m_csMonitor = pcms -> pDisplayName;
  402. m_csPrinter = pcms -> pPrinterName;
  403. // Ansi version call
  404. m_bAnsiCall = TRUE;
  405. CompleteInitialization();
  406. // Display the UI, and watch what happens...
  407. switch (DoModal()) {
  408. case IDOK:
  409. if (!m_bSuccess)
  410. return;
  411. // Fill up return buffer.
  412. FillStructure(pcms);
  413. return;
  414. case IDCANCEL:
  415. Fail(ERROR_SUCCESS);
  416. return;
  417. default:
  418. Fail(GetLastError());
  419. }
  420. }
  421. CColorMatchDialog::CColorMatchDialog(COLORMATCHSETUPW *pcms) :
  422. CDialog(CGlobals::Instance(), ApplicationUI, pcms -> hwndOwner) {
  423. if (!GoodParms((PCOLORMATCHSETUP) pcms))
  424. return;
  425. // Make sure we've initialized these, if we have to.
  426. if (pcms -> dwFlags & CMS_SETMONITORPROFILE) {
  427. m_csMonitorProfile = pcms -> pMonitorProfile;
  428. m_csMonitorProfile = m_csMonitorProfile.NameAndExtension();
  429. }
  430. if (pcms -> dwFlags & CMS_SETPRINTERPROFILE) {
  431. m_csPrinterProfile = pcms -> pPrinterProfile;
  432. m_csPrinterProfile = m_csPrinterProfile.NameAndExtension();
  433. }
  434. if (pcms -> dwFlags & CMS_SETTARGETPROFILE) {
  435. m_csTargetProfile = pcms -> pTargetProfile;
  436. m_csTargetProfile = m_csTargetProfile.NameAndExtension();
  437. }
  438. m_csSource = pcms -> pSourceName;
  439. m_csMonitor = pcms -> pDisplayName;
  440. m_csPrinter = pcms -> pPrinterName;
  441. // Unicode version call
  442. m_bAnsiCall = FALSE;
  443. CompleteInitialization();
  444. // Display the UI, and watch what happens...
  445. switch (DoModal()) {
  446. case IDOK:
  447. if (!m_bSuccess)
  448. return;
  449. // Fill up return buffer.
  450. FillStructure(pcms);
  451. return;
  452. case IDCANCEL:
  453. Fail(ERROR_SUCCESS);
  454. return;
  455. default:
  456. Fail(GetLastError());
  457. }
  458. }
  459. // Dialog initialization function
  460. BOOL CColorMatchDialog::OnInit() {
  461. // Collect the common handles
  462. m_hwndRenderIntent = GetDlgItem(m_hwnd, RenderingIntent);
  463. m_hwndTargetIntent = GetDlgItem(m_hwnd, TargetIntent);
  464. m_hwndPrinterList = GetDlgItem(m_hwnd, PrinterProfile);
  465. m_hwndMonitorList = GetDlgItem(m_hwnd, MonitorProfile);
  466. m_hwndTargetList = GetDlgItem(m_hwnd, TargetProfile);
  467. m_hwndMonitorProfileLabel = GetDlgItem(m_hwnd, MonitorProfileLabel);
  468. m_hwndPrinterProfileLabel = GetDlgItem(m_hwnd, PrinterProfileLabel);
  469. m_hwndIntentLabel = GetDlgItem(m_hwnd, RenderingIntentLabel);
  470. m_hwndTargetProfileLabel = GetDlgItem(m_hwnd, TargetProfileLabel);
  471. m_hwndTargetIntentLabel = GetDlgItem(m_hwnd, TargetIntentLabel);
  472. m_hwndIntentText1 = GetDlgItem(m_hwnd, RenderingIntentText1);
  473. // Fill in the source name
  474. SetDlgItemText(m_hwnd, SourceProfile, m_csSource);
  475. // Set the Check Boxes
  476. CheckDlgButton(m_hwnd, EnableICM,
  477. m_bEnableICM ? BST_CHECKED : BST_UNCHECKED);
  478. CheckDlgButton(m_hwnd, EnableBasic,
  479. m_bEnableProofing ? BST_UNCHECKED : BST_CHECKED);
  480. CheckDlgButton(m_hwnd, EnableProofing,
  481. m_bEnableProofing ? BST_CHECKED : BST_UNCHECKED);
  482. // Fill in the list(s) of Rendering Intents
  483. CString csWork; // There's plenty of it to do...
  484. for (int i = INTENT_PERCEPTUAL; i <= INTENT_ABSOLUTE_COLORIMETRIC; i++) {
  485. csWork.Load(i + PerceptualString);
  486. SendMessage(m_hwndRenderIntent, CB_ADDSTRING, 0,
  487. (LPARAM) (LPCTSTR) csWork);
  488. SendMessage(m_hwndTargetIntent, CB_ADDSTRING, 0,
  489. (LPARAM) (LPCTSTR) csWork);
  490. }
  491. // Init the rendering intents
  492. SendMessage(m_hwndRenderIntent, CB_SETCURSEL, m_dwRenderIntent, 0);
  493. SendMessage(m_hwndTargetIntent, CB_SETCURSEL, m_dwProofIntent, 0);
  494. // Init the profile lists
  495. // 03-20-1997 [email protected] RAID Memphis:22213
  496. // The algorithm used to determine which profile to select was incorrect.
  497. // There's a much simpler and direct way, anyway.
  498. LRESULT id;
  499. // Target Profiles
  500. for (unsigned u = 0; u < m_csaTarget.Count(); u++) {
  501. if (m_bUseProfileDescription) {
  502. id = SendMessage(m_hwndTargetList, CB_ADDSTRING,
  503. 0, (LPARAM)((LPTSTR) m_csaTargetDesc[u]));
  504. } else {
  505. id = SendMessage(m_hwndTargetList, CB_ADDSTRING,
  506. 0, m_csaTarget[u].NameOnly());
  507. }
  508. SendMessage(m_hwndTargetList, CB_SETITEMDATA, id, u);
  509. if (m_csaTarget[u].IsEqualString(m_csTargetProfile)) {
  510. SendMessage(m_hwndTargetList, CB_SETCURSEL, id, 0);
  511. }
  512. }
  513. // Set Target profile if specified, otherwise the default
  514. if (!m_csaTarget.Count()) {
  515. CString csWork;
  516. csWork.Load(NoProfileString);
  517. SendMessage(m_hwndTargetList, CB_ADDSTRING, 0, csWork);
  518. SendMessage(m_hwndTargetList, CB_SETITEMDATA, 0, -1);
  519. SendMessage(m_hwndTargetList, CB_SETCURSEL, 0, 0);
  520. }
  521. // Monitor Profiles
  522. // 03-20-1997 [email protected] Memphis RAID #22289
  523. csWork.Load(GetDlgItem(m_hwnd, MonitorProfileLabel));
  524. csWork = csWork + m_csMonitorDisplayName + _TEXT(")");
  525. SetDlgItemText(m_hwnd, MonitorProfileLabel, csWork);
  526. for (u = 0; u < m_csaMonitor.Count(); u++) {
  527. if (m_bUseProfileDescription) {
  528. id = SendMessage(m_hwndMonitorList, CB_ADDSTRING,
  529. 0, (LPARAM)((LPTSTR) m_csaMonitorDesc[u]));
  530. } else {
  531. id = SendMessage(m_hwndMonitorList, CB_ADDSTRING,
  532. 0, m_csaMonitor[u].NameOnly());
  533. }
  534. SendMessage(m_hwndMonitorList, CB_SETITEMDATA, id, u);
  535. if (m_csaMonitor[u].IsEqualString(m_csMonitorProfile)) {
  536. SendMessage(m_hwndMonitorList, CB_SETCURSEL, id, 0);
  537. }
  538. }
  539. // Set Monitor profile if specified
  540. if (!m_csaMonitor.Count()) {
  541. CString csWork;
  542. csWork.Load(NoProfileString);
  543. SendMessage(m_hwndMonitorList, CB_ADDSTRING, 0, csWork);
  544. SendMessage(m_hwndMonitorList, CB_SETITEMDATA, 0, -1);
  545. SendMessage(m_hwndMonitorList, CB_SETCURSEL, 0, 0);
  546. }
  547. // Printer Profiles
  548. // 03-20-1997 [email protected] RAID Memphis:22290
  549. // If there's no printer, then we should disable all of the related
  550. // controls.
  551. if (m_csPrinter.IsEmpty()) {
  552. csWork.Load(NoPrintersInstalled);
  553. } else {
  554. csWork.Load(GetDlgItem(m_hwnd, PrinterProfileLabel));
  555. csWork = csWork + m_csPrinter + _TEXT(")");
  556. }
  557. SetDlgItemText(m_hwnd, PrinterProfileLabel, csWork);
  558. for (u = 0; u < m_csaPrinter.Count(); u++) {
  559. if (m_bUseProfileDescription) {
  560. id = SendMessage(m_hwndPrinterList, CB_ADDSTRING,
  561. 0, (LPARAM)((LPTSTR) m_csaPrinterDesc[u]));
  562. } else {
  563. id = SendMessage(m_hwndPrinterList, CB_ADDSTRING,
  564. 0, m_csaPrinter[u].NameOnly());
  565. }
  566. SendMessage(m_hwndPrinterList, CB_SETITEMDATA, id, u);
  567. if (m_csaPrinter[u].IsEqualString(m_csPrinterProfile)) {
  568. SendMessage(m_hwndPrinterList, CB_SETCURSEL, id, 0);
  569. }
  570. }
  571. // Set Printer profile if specified
  572. if (!m_csaPrinter.Count()) {
  573. CString csWork;
  574. if (!m_csPrinter.IsEmpty() && !m_bColorPrinter) {
  575. // Printer are specified, but it is not color printer.
  576. csWork.Load(NotColorPrinter);
  577. } else {
  578. csWork.Load(NoProfileString);
  579. }
  580. SendMessage(m_hwndPrinterList, CB_ADDSTRING, 0, csWork);
  581. SendMessage(m_hwndPrinterList, CB_SETITEMDATA, 0, -1);
  582. SendMessage(m_hwndPrinterList, CB_SETCURSEL, 0, 0);
  583. }
  584. // End RAID Memphis:22213, 22289, 22290 03-20-1997
  585. // If Apply callback does not provided, disable apply button.
  586. if (m_dpApplyCallback == NULL) {
  587. RECT rcApply, rcCancel;
  588. POINT ptApply, ptCancel;
  589. // Get current "Apply" and "Cancel" buttom position
  590. GetWindowRect(GetDlgItem(m_hwnd, ApplyButton), &rcApply);
  591. GetWindowRect(GetDlgItem(m_hwnd, IDCANCEL), &rcCancel);
  592. // Convert the buttom coordinate to parent dialog coord from screen coord.
  593. ptApply.x = rcApply.left; ptApply.y = rcApply.top;
  594. ptCancel.x = rcCancel.left; ptCancel.y = rcCancel.top;
  595. ScreenToClient(m_hwnd,&ptApply);
  596. ScreenToClient(m_hwnd,&ptCancel);
  597. // Move "Apply" button away... and shift "Cancel" and "OK"
  598. MoveWindow(GetDlgItem(m_hwnd, ApplyButton),0,0,0,0,TRUE);
  599. MoveWindow(GetDlgItem(m_hwnd, IDCANCEL),
  600. ptApply.x,ptApply.y,
  601. rcApply.right - rcApply.left,
  602. rcApply.bottom - rcApply.top,TRUE);
  603. MoveWindow(GetDlgItem(m_hwnd, IDOK),
  604. ptCancel.x,ptCancel.y,
  605. rcCancel.right - rcCancel.left,
  606. rcCancel.bottom - rcCancel.top,TRUE);
  607. }
  608. // Enable/Disable controls based upon settings
  609. UpdateControls(FALSE);
  610. return FALSE; // Because we've probably moved it...
  611. }
  612. // Command Processing override
  613. BOOL CColorMatchDialog::OnCommand(WORD wNotifyCode, WORD wid, HWND hwndCtl) {
  614. switch (wNotifyCode) {
  615. case BN_CLICKED:
  616. switch (wid) {
  617. case EnableICM:
  618. m_bEnableICM = !m_bEnableICM;
  619. UpdateControls(TRUE);
  620. return TRUE;
  621. case EnableBasic:
  622. if (m_bEnableProofing)
  623. {
  624. m_bEnableProofing = FALSE;
  625. // Copy proof intent to rendering intent
  626. //
  627. m_dwRenderIntent = m_dwProofIntent;
  628. // Update UI
  629. //
  630. SendMessage(m_hwndTargetIntent, CB_SETCURSEL,
  631. m_dwProofIntent, 0);
  632. SendMessage(m_hwndRenderIntent, CB_SETCURSEL,
  633. m_dwRenderIntent, 0);
  634. UpdateControls(TRUE);
  635. }
  636. return TRUE;
  637. case EnableProofing:
  638. if (m_bEnableProofing == FALSE)
  639. {
  640. m_bEnableProofing = TRUE;
  641. // Copy the original rendering intent to the proofing
  642. // intent, and set original to Absolute Colorimetric
  643. m_dwProofIntent = m_dwRenderIntent;
  644. m_dwRenderIntent = INTENT_ABSOLUTE_COLORIMETRIC;
  645. // Update UI
  646. //
  647. SendMessage(m_hwndTargetIntent, CB_SETCURSEL,
  648. m_dwProofIntent, 0);
  649. SendMessage(m_hwndRenderIntent, CB_SETCURSEL,
  650. m_dwRenderIntent, 0);
  651. UpdateControls(TRUE);
  652. }
  653. return TRUE;
  654. case ApplyButton: {
  655. // Disable apply button
  656. EnableApplyButton(FALSE);
  657. // Callback supplied function
  658. if (m_dpApplyCallback) {
  659. if (m_bAnsiCall) {
  660. PCOLORMATCHSETUPA pcms = (PCOLORMATCHSETUPA) m_pvCMS;
  661. FillStructure(pcms);
  662. (*(PCMSCALLBACKA)m_dpApplyCallback)(pcms,m_lpApplyCallback);
  663. } else {
  664. PCOLORMATCHSETUPW pcms = (PCOLORMATCHSETUPW) m_pvCMS;
  665. FillStructure(pcms);
  666. (*(PCMSCALLBACKW)m_dpApplyCallback)(pcms,m_lpApplyCallback);
  667. }
  668. }
  669. return TRUE;
  670. }
  671. }
  672. break;
  673. case CBN_SELCHANGE: {
  674. DWORD idItem = (DWORD)SendMessage(hwndCtl, CB_GETCURSEL, 0, 0);
  675. unsigned uItem = (unsigned)SendMessage(hwndCtl, CB_GETITEMDATA, idItem, 0);
  676. switch (wid) {
  677. case RenderingIntent:
  678. if (m_dwRenderIntent != idItem)
  679. {
  680. m_dwRenderIntent = idItem;
  681. // If proofing is disabled, proof intent follows
  682. // render intent
  683. if (! m_bEnableProofing)
  684. {
  685. m_dwProofIntent = idItem;
  686. SendMessage(m_hwndTargetIntent, CB_SETCURSEL,
  687. m_dwProofIntent, 0);
  688. }
  689. EnableApplyButton();
  690. }
  691. return TRUE;
  692. case TargetIntent:
  693. if (m_dwProofIntent != idItem)
  694. {
  695. m_dwProofIntent = idItem;
  696. EnableApplyButton();
  697. }
  698. return TRUE;
  699. case TargetProfile:
  700. // If there are no installed profiles, don't bother
  701. if (!m_csaTarget.Count())
  702. return TRUE;
  703. if (m_csTargetProfile.IsEqualString(m_csaTarget[uItem]) == FALSE)
  704. {
  705. m_csTargetProfile = m_csaTarget[uItem];
  706. EnableApplyButton();
  707. }
  708. return TRUE;
  709. case MonitorProfile:
  710. // If there are no installed profiles, don't bother
  711. if (!m_csaMonitor.Count())
  712. return TRUE;
  713. if (m_csMonitorProfile.IsEqualString(m_csaMonitor[uItem]) == FALSE)
  714. {
  715. m_csMonitorProfile = m_csaMonitor[uItem];
  716. EnableApplyButton();
  717. }
  718. return TRUE;
  719. case PrinterProfile:
  720. // If there are no installed profiles, don't bother
  721. if (!m_csaPrinter.Count())
  722. return TRUE;
  723. if (m_csPrinterProfile.IsEqualString(m_csaPrinter[uItem]) == FALSE)
  724. {
  725. m_csPrinterProfile = m_csaPrinter[uItem];
  726. EnableApplyButton();
  727. }
  728. return TRUE;
  729. }
  730. }
  731. }
  732. // Pass anything we didn't handle above to the base class
  733. return CDialog::OnCommand(wNotifyCode, wid, hwndCtl);
  734. }
  735. // Context-sensitive help handler
  736. BOOL CColorMatchDialog::OnHelp(LPHELPINFO pHelp) {
  737. if (pHelp->iContextType == HELPINFO_WINDOW) {
  738. WinHelp((HWND) pHelp->hItemHandle, WINDOWS_HELP_FILE,
  739. HELP_WM_HELP, (ULONG_PTR) (LPSTR) ApplicationUIHelpIds);
  740. }
  741. return (TRUE);
  742. }
  743. BOOL CColorMatchDialog::OnContextMenu(HWND hwnd) {
  744. WinHelp(hwnd, WINDOWS_HELP_FILE,
  745. HELP_CONTEXTMENU, (ULONG_PTR) (LPSTR) ApplicationUIHelpIds);
  746. return (TRUE);
  747. }
  748. // This are the real honest-to-goodness API!
  749. extern "C" BOOL WINAPI SetupColorMatchingA(PCOLORMATCHSETUPA pcms) {
  750. CColorMatchDialog ccmd(pcms);
  751. return ccmd.Results();
  752. }
  753. extern "C" BOOL WINAPI SetupColorMatchingW(PCOLORMATCHSETUPW pcms) {
  754. CColorMatchDialog ccmd(pcms);
  755. return ccmd.Results();
  756. }