00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "precomp.h"
00028 #include "resource.h"
00029 #include "debug.h"
00030 #include "oemui.h"
00031 #include "winbase.h"
00032 #include "helpers.h"
00033
00034 #include "CCPDFPropPage.h"
00035 #include "CCLicensePropPage.h"
00036 #include <PRCOMOEM.H>
00037
00038
00040
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00058 struct DocUserData
00059 {
00060 public:
00061
00066 DocUserData(POEMDEV p, HANDLE h) : pDevMode(p), bSave(false), hPrinter(h) {};
00067
00068 public:
00069
00071 POEMDEV pDevMode;
00073 bool bSave;
00075 HANDLE hPrinter;
00076 };
00077
00079
00081
00083 static HRESULT hrDocumentPropertyPage(POEMCUIPPARAM pOEMUIParam);
00085 static HRESULT hrPrinterPropertyPage(POEMCUIPPARAM pOEMUIParam);
00087 LONG APIENTRY OEMPrinterUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam);
00089 LONG APIENTRY OEMDocUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam);
00091 static POPTITEM CreateOptItems(HANDLE hHeap, DWORD dwOptItems);
00093 static void InitOptItems(POPTITEM pOptItems, DWORD dwOptItems);
00095 static POPTTYPE CreateOptType(HANDLE hHeap, WORD wOptParams);
00097 static PTSTR GetStringResource(HANDLE hHeap, HANDLE hModule, UINT uResource);
00098
00099
00100
00106 HRESULT hrOEMPropertyPage(DWORD dwMode, POEMCUIPPARAM pOEMUIParam)
00107 {
00108 HRESULT hResult = S_OK;
00109
00110 VERBOSE(DLLTEXT("hrOEMPropertyPage(%d) entry.\r\n"), dwMode);
00111
00112
00113 if( (OEMCUIP_DOCPROP != dwMode)
00114 &&
00115 (OEMCUIP_PRNPROP != dwMode)
00116 )
00117 {
00118 ERR(ERRORTEXT("hrOEMPropertyPage() ERROR_INVALID_PARAMETER.\r\n"));
00119 VERBOSE(DLLTEXT("\tdwMode = %d, pOEMUIParam = %#lx.\r\n"), dwMode, pOEMUIParam);
00120
00121
00122 SetLastError(ERROR_INVALID_PARAMETER);
00123 return E_FAIL;
00124 }
00125
00126 switch(dwMode)
00127 {
00128 case OEMCUIP_DOCPROP:
00129
00130 hResult = hrDocumentPropertyPage(pOEMUIParam);
00131 break;
00132
00133 case OEMCUIP_PRNPROP:
00134
00135 hResult = hrPrinterPropertyPage(pOEMUIParam);
00136 break;
00137
00138 default:
00139
00140 ERR(ERRORTEXT("hrOEMPropertyPage() Invalid dwMode, %d"), dwMode);
00141 SetLastError(ERROR_INVALID_PARAMETER);
00142 hResult = E_FAIL;
00143 break;
00144 }
00145
00146 return hResult;
00147 }
00148
00153 static HRESULT hrDocumentPropertyPage(POEMCUIPPARAM pOEMUIParam)
00154 {
00155
00156 if (pOEMUIParam->pDrvOptItems != NULL)
00157 {
00158 for (UINT i=0;i<pOEMUIParam->cDrvOptItems; i++)
00159 {
00160 if (pOEMUIParam->pDrvOptItems[i].DMPubID == DMPUB_DEFSOURCE)
00161 pOEMUIParam->pDrvOptItems[i].Flags |= OPTIF_HIDE;
00162 }
00163 }
00164
00165 if(NULL == pOEMUIParam->pOEMOptItems)
00166 {
00167
00168 pOEMUIParam->cOEMOptItems = 1;
00169
00170 VERBOSE(DLLTEXT("hrDocumentPropertyPage() requesting %d number of items.\r\n"), pOEMUIParam->cOEMOptItems);
00171 }
00172 else
00173 {
00174 POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM;
00175
00176 VERBOSE(DLLTEXT("hrDocumentPropertyPage() fill out %d items.\r\n"), pOEMUIParam->cOEMOptItems);
00177
00178
00179 pOEMUIParam->OEMCUIPCallback = OEMDocUICallBack;
00180
00181
00182 InitOptItems(pOEMUIParam->pOEMOptItems, pOEMUIParam->cOEMOptItems);
00183
00184
00185
00186 pOEMUIParam->pOEMOptItems[0].Level = 1;
00187 pOEMUIParam->pOEMOptItems[0].DlgPageIdx = 0;
00188 pOEMUIParam->pOEMOptItems[0].Flags = OPTIF_CALLBACK;
00189 pOEMUIParam->pOEMOptItems[0].pName = GetStringResource(pOEMUIParam->hOEMHeap, pOEMUIParam->hModule, IDS_AUTOOPEN);
00190 if (CanOpenPDFFiles())
00191 pOEMUIParam->pOEMOptItems[0].Sel = pOEMDev->bAutoOpen ? 1 : 0;
00192 else
00193 {
00194 pOEMUIParam->pOEMOptItems[0].Sel = 0;
00195 pOEMUIParam->pOEMOptItems[0].Flags |= OPTIF_DISABLED;
00196 }
00197 pOEMUIParam->pOEMOptItems[0].DMPubID = DMPUB_USER;
00198
00199 pOEMUIParam->pOEMOptItems[0].pOptType = CreateOptType(pOEMUIParam->hOEMHeap, 1);
00200
00201 pOEMUIParam->pOEMOptItems[0].pOptType->Type = TVOT_CHKBOX;
00202 pOEMUIParam->pOEMOptItems[0].pOptType->pOptParam[0].IconID = 0;
00203 }
00204
00205 return S_OK;
00206 }
00207
00212 static HRESULT hrPrinterPropertyPage(POEMCUIPPARAM pOEMUIParam)
00213 {
00214 if(NULL == pOEMUIParam->pOEMOptItems)
00215 {
00216
00217 pOEMUIParam->cOEMOptItems = 1;
00218
00219 VERBOSE(DLLTEXT("hrPrinterPropertyPage() requesting %d number of items.\r\n"), pOEMUIParam->cOEMOptItems);
00220 }
00221 else
00222 {
00223 DWORD dwValue, dwSize, dwRet;
00224
00225 VERBOSE(DLLTEXT("hrPrinterPropertyPage() fill out %d items.\r\n"), pOEMUIParam->cOEMOptItems);
00226
00227
00228 dwSize = sizeof(dwValue);
00229 dwRet = GetPrinterData(pOEMUIParam->hPrinter, (LPTSTR)SETTINGS_AUTOOPEN, NULL, (LPBYTE)&dwValue, sizeof(DWORD), &dwSize);
00230 if (dwRet != ERROR_SUCCESS)
00231 dwValue = 1;
00232 bool bAutoOpen = (dwValue == 1);
00233
00234
00235 pOEMUIParam->OEMCUIPCallback = OEMPrinterUICallBack;
00236
00237
00238 InitOptItems(pOEMUIParam->pOEMOptItems, pOEMUIParam->cOEMOptItems);
00239
00240
00241
00242 pOEMUIParam->pOEMOptItems[0].Level = 1;
00243 pOEMUIParam->pOEMOptItems[0].DlgPageIdx = 0;
00244 pOEMUIParam->pOEMOptItems[0].Flags = OPTIF_CALLBACK;
00245 pOEMUIParam->pOEMOptItems[0].pName = GetStringResource(pOEMUIParam->hOEMHeap, pOEMUIParam->hModule, IDS_AUTOOPEN);
00246 if (CanOpenPDFFiles())
00247 pOEMUIParam->pOEMOptItems[0].Sel = bAutoOpen ? 1 : 0;
00248 else
00249 {
00250 pOEMUIParam->pOEMOptItems[0].Sel = 0;
00251 pOEMUIParam->pOEMOptItems[0].Flags |= OPTIF_DISABLED;
00252 }
00253 pOEMUIParam->pOEMOptItems[0].DMPubID = DMPUB_USER;
00254
00255 pOEMUIParam->pOEMOptItems[0].pOptType = CreateOptType(pOEMUIParam->hOEMHeap, 1);
00256
00257 pOEMUIParam->pOEMOptItems[0].pOptType->Type = TVOT_CHKBOX;
00258 pOEMUIParam->pOEMOptItems[0].pOptType->pOptParam[0].IconID = 0;
00259 pOEMUIParam->pOEMOptItems[0].pOptType->Count = 1;
00260 }
00261
00262 return S_OK;
00263 }
00264
00265
00272 HRESULT hrOEMDocumentPropertySheets(PPROPSHEETUI_INFO pPSUIInfo, LPARAM lParam, IPrintOemDriverUI* pOEMHelp)
00273 {
00274 LONG_PTR lResult;
00275
00276
00277 if( (NULL == pPSUIInfo)
00278 ||
00279 (PROPSHEETUI_INFO_VERSION != pPSUIInfo->Version)
00280 )
00281 {
00282 ERR(ERRORTEXT("OEMDocumentPropertySheets() ERROR_INVALID_PARAMETER.\r\n"));
00283
00284
00285 SetLastError(ERROR_INVALID_PARAMETER);
00286 return E_FAIL;
00287 }
00288
00289 VERBOSE(DLLTEXT("OEMDocumentPropertySheets(Reason: %d) entry.\r\n"), pPSUIInfo->Reason);
00290
00291
00292
00293 switch(pPSUIInfo->Reason)
00294 {
00295 case PROPSHEETUI_REASON_INIT:
00296 {
00297
00298 POEMUIPSPARAM pOEMUIParam = (POEMUIPSPARAM) pPSUIInfo->lParamInit;
00299 POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM;
00300
00301 PROPSHEETPAGE Page;
00302
00303
00304 CCLicensePropPage* pLicense = new CCLicensePropPage(pOEMUIParam->hPrinter, pOEMHelp, pOEMDev, pOEMUIParam->pPublicDM);
00305 pLicense->PreparePage(Page);
00306
00307
00308 lResult = pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet, CPSFUNC_ADD_PROPSHEETPAGE, (LPARAM)&Page, 0);
00309 pLicense->SetCallbackData(pPSUIInfo->pfnComPropSheet, pPSUIInfo->hComPropSheet, (HANDLE)lResult);
00310
00311
00312 CCPDFPropPage* pPDF = new CCPDFPropPage(pOEMUIParam->hPrinter, pOEMHelp, pOEMDev);
00313 pPDF->PreparePage(Page);
00314
00315
00316 lResult = pPSUIInfo->pfnComPropSheet(pPSUIInfo->hComPropSheet, CPSFUNC_ADD_PROPSHEETPAGE, (LPARAM)&Page, 0);
00317 pPDF->SetCallbackData(pPSUIInfo->pfnComPropSheet, pPSUIInfo->hComPropSheet, (HANDLE)lResult);
00318
00319 pPSUIInfo->UserData = (DWORD)new DocUserData(pOEMDev, pOEMUIParam->hPrinter);
00320 }
00321 break;
00322
00323 case PROPSHEETUI_REASON_GET_INFO_HEADER:
00324 {
00325
00326 PPROPSHEETUI_INFO_HEADER pHeader = (PPROPSHEETUI_INFO_HEADER) lParam;
00327
00328 lResult = TRUE;
00329 }
00330 break;
00331
00332 case PROPSHEETUI_REASON_GET_ICON:
00333
00334 lResult = 0;
00335 break;
00336
00337 case PROPSHEETUI_REASON_SET_RESULT:
00338 {
00339
00340 PSETRESULT_INFO pInfo = (PSETRESULT_INFO) lParam;
00341
00342 lResult = pInfo->Result;
00343 if (lResult == 1)
00344 {
00345 if (pPSUIInfo->UserData != NULL)
00346 {
00347 DocUserData* pData = (DocUserData*)pPSUIInfo->UserData;
00348 pData->bSave = true;
00349 }
00350 }
00351 }
00352 break;
00353
00354 case PROPSHEETUI_REASON_DESTROY:
00355
00356 lResult = TRUE;
00357 if (pPSUIInfo->UserData != NULL)
00358 {
00359 DocUserData* pData = (DocUserData*)pPSUIInfo->UserData;
00360
00361 if (pData->bSave)
00362 WriteOEMDevToRegistry(pData->pDevMode, pData->hPrinter);
00363
00364 delete pData;
00365 pPSUIInfo->UserData = 0;
00366 }
00367 break;
00368 }
00369
00370 pPSUIInfo->Result = lResult;
00371 return S_OK;
00372 }
00373
00380 HRESULT hrOEMDevicePropertySheets(PPROPSHEETUI_INFO pPSUIInfo, LPARAM lParam, IPrintOemDriverUI* pOEMHelp)
00381 {
00382 LONG_PTR lResult;
00383
00384 VERBOSE(DLLTEXT("hrOEMDevicePropertySheets(%#x, %#x) entry\r\n"), pPSUIInfo, lParam);
00385
00386
00387 if( (NULL == pPSUIInfo)
00388 ||
00389 (PROPSHEETUI_INFO_VERSION != pPSUIInfo->Version)
00390 )
00391 {
00392 ERR(ERRORTEXT("hrOEMDevicePropertySheets() ERROR_INVALID_PARAMETER.\r\n"));
00393
00394
00395 SetLastError(ERROR_INVALID_PARAMETER);
00396 return E_FAIL;
00397 }
00398
00399 Dump(pPSUIInfo);
00400
00401
00402 switch(pPSUIInfo->Reason)
00403 {
00404 case PROPSHEETUI_REASON_INIT:
00405
00406 break;
00407
00408 case PROPSHEETUI_REASON_GET_INFO_HEADER:
00409 {
00410
00411 PPROPSHEETUI_INFO_HEADER pHeader = (PPROPSHEETUI_INFO_HEADER) lParam;
00412
00413 lResult = TRUE;
00414 }
00415 break;
00416
00417 case PROPSHEETUI_REASON_GET_ICON:
00418
00419 lResult = 0;
00420 break;
00421
00422 case PROPSHEETUI_REASON_SET_RESULT:
00423 {
00424
00425 PSETRESULT_INFO pInfo = (PSETRESULT_INFO) lParam;
00426
00427 lResult = pInfo->Result;
00428 }
00429 break;
00430
00431 case PROPSHEETUI_REASON_DESTROY:
00432
00433 lResult = TRUE;
00434 break;
00435 }
00436
00437 pPSUIInfo->Result = lResult;
00438 return S_OK;
00439 }
00440
00446 LONG APIENTRY OEMPrinterUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam)
00447 {
00448 LONG lReturn = CPSUICB_ACTION_NONE;
00449 POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM;
00450
00451 VERBOSE(DLLTEXT("OEMPrinterUICallBack() entry, Reason is %d.\r\n"), pCallbackParam->Reason);
00452
00453 switch(pCallbackParam->Reason)
00454 {
00455 case CPSUICB_REASON_APPLYNOW:
00456 {
00457 DWORD dwValue = pOEMUIParam->pOEMOptItems[0].Sel;
00458
00459
00460 if (SetPrinterData(pOEMUIParam->hPrinter, SETTINGS_AUTOOPEN, REG_DWORD, (PBYTE)&dwValue, sizeof(DWORD)) == ERROR_SUCCESS)
00461
00462 lReturn = CPSUICB_ACTION_ITEMS_APPLIED;
00463 }
00464 break;
00465
00466 default:
00467 break;
00468 }
00469
00470 return lReturn;
00471 }
00472
00478 LONG APIENTRY OEMDocUICallBack(PCPSUICBPARAM pCallbackParam, POEMCUIPPARAM pOEMUIParam)
00479 {
00480
00481 LONG lReturn = CPSUICB_ACTION_NONE;
00482 POEMDEV pOEMDev = (POEMDEV) pOEMUIParam->pOEMDM;
00483
00484 VERBOSE(DLLTEXT("OEMDocUICallBack() entry, Reason is %d.\r\n"), pCallbackParam->Reason);
00485
00486 switch(pCallbackParam->Reason)
00487 {
00488 case CPSUICB_REASON_SEL_CHANGED:
00489
00490 break;
00491
00492 case CPSUICB_REASON_APPLYNOW:
00493
00494 pOEMDev->bAutoOpen = pOEMUIParam->pOEMOptItems[0].Sel == 1;
00495
00496 WriteOEMDevToRegistry(pOEMDev, pOEMUIParam->hPrinter);
00497 lReturn = CPSUICB_ACTION_ITEMS_APPLIED;
00498 break;
00499
00500 case CPSUICB_REASON_KILLACTIVE:
00501
00502 pOEMDev->bAutoOpen = pOEMUIParam->pOEMOptItems[0].Sel == 1;
00503 break;
00504
00505 case CPSUICB_REASON_SETACTIVE:
00506 case CPSUICB_REASON_ITEMS_REVERTED:
00507
00508 pOEMUIParam->pOEMOptItems[0].Sel = pOEMDev->bAutoOpen ? 1 : 0;
00509 pOEMUIParam->pOEMOptItems[0].Flags |= OPTIF_CHANGED;
00510 lReturn = CPSUICB_ACTION_OPTIF_CHANGED;
00511 break;
00512
00513 default:
00514 break;
00515 }
00516
00517 return lReturn;
00518 }
00519
00525 static POPTITEM CreateOptItems(HANDLE hHeap, DWORD dwOptItems)
00526 {
00527 POPTITEM pOptItems = NULL;
00528
00529
00530 pOptItems = (POPTITEM) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(OPTITEM) * dwOptItems);
00531 if(NULL != pOptItems)
00532 {
00533
00534 InitOptItems(pOptItems, dwOptItems);
00535 }
00536 else
00537 {
00538 ERR(ERRORTEXT("CreateOptItems() failed to allocate memory for OPTITEMs!\r\n"));
00539 }
00540
00541 return pOptItems;
00542 }
00543
00548 static void InitOptItems(POPTITEM pOptItems, DWORD dwOptItems)
00549 {
00550 VERBOSE(DLLTEXT("InitOptItems() entry.\r\n"));
00551 if (dwOptItems == 0)
00552 return;
00553
00554
00555 memset(pOptItems, 0, sizeof(OPTITEM) * dwOptItems);
00556
00557
00558 for(DWORD dwCount = 0; dwCount < dwOptItems; dwCount++)
00559 {
00560 pOptItems[dwCount].cbSize = sizeof(OPTITEM);
00561 pOptItems[dwCount].DMPubID = DMPUB_NONE;
00562 }
00563 }
00564
00570 static POPTTYPE CreateOptType(HANDLE hHeap, WORD wOptParams)
00571 {
00572 POPTTYPE pOptType = NULL;
00573
00574 VERBOSE(DLLTEXT("CreateOptType() entry.\r\n"));
00575
00576
00577 pOptType = (POPTTYPE) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, sizeof(OPTTYPE));
00578 if(NULL != pOptType)
00579 {
00580
00581 pOptType->cbSize = sizeof(OPTTYPE);
00582 pOptType->Count = wOptParams;
00583
00584
00585 pOptType->pOptParam = (POPTPARAM) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, wOptParams * sizeof(OPTPARAM));
00586 if(NULL != pOptType->pOptParam)
00587 {
00588
00589 for(WORD wCount = 0; wCount < wOptParams; wCount++)
00590 {
00591 pOptType->pOptParam[wCount].cbSize = sizeof(OPTPARAM);
00592 }
00593 }
00594 else
00595 {
00596 ERR(ERRORTEXT("CreateOptType() failed to allocated memory for OPTPARAMs!\r\n"));
00597
00598
00599 HeapFree(hHeap, 0, pOptType);
00600 pOptType = NULL;
00601 }
00602 }
00603 else
00604 {
00605 ERR(ERRORTEXT("CreateOptType() failed to allocated memory for OPTTYPE!\r\n"));
00606 }
00607
00608 return pOptType;
00609 }
00610
00617 static PTSTR GetStringResource(HANDLE hHeap, HANDLE hModule, UINT uResource)
00618 {
00619 int nResult;
00620 DWORD dwSize = MAX_PATH;
00621 PTSTR pszString = NULL;
00622
00623 VERBOSE(DLLTEXT("GetStringResource(%#x, %#x, %d) entered.\r\n"), hHeap, hModule, uResource);
00624
00625
00626 pszString = (PTSTR) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, dwSize * sizeof(TCHAR));
00627 if(NULL != pszString)
00628 {
00629
00630 nResult = LoadString((HMODULE)hModule, uResource, pszString, dwSize);
00631 if(nResult > 0)
00632 {
00633 PTSTR pszTemp;
00634
00635
00636 VERBOSE(DLLTEXT("LoadString() returned %d!\r\n"), nResult);
00637 VERBOSE(DLLTEXT("String load was \"%s\".\r\n"), pszString);
00638
00639 pszTemp = (PTSTR) HeapReAlloc(hHeap, HEAP_ZERO_MEMORY, pszString, (nResult + 1) * sizeof(TCHAR));
00640 if(NULL != pszTemp)
00641 {
00642 pszString = pszTemp;
00643 }
00644 else
00645 {
00646 ERR(ERRORTEXT("GetStringResource() HeapReAlloc() of string retrieved failed! (Last Error was %d)\r\n"), GetLastError());
00647 }
00648 }
00649 else
00650 {
00651 ERR(ERRORTEXT("LoadString() returned %d! (Last Error was %d)\r\n"), nResult, GetLastError());
00652 ERR(ERRORTEXT("GetStringResource() failed to load string resource %d!\r\n"), uResource);
00653
00654 pszString = NULL;
00655 }
00656 }
00657 else
00658 {
00659 ERR(ERRORTEXT("GetStringResource() failed to allocate string buffer!\r\n"));
00660 }
00661
00662 return pszString;
00663 }