UINT CreateFormOI( PPRINTERINFO pPI, POPTITEM pOptItem, POIDATA pOIData ) /*++ Routine Description: This function add the available forms to the combo box, it will optionally add the roll feed type of form Arguments: pPI - Pointer to the PRINTERINFO data structure pOptItem - Pointer to the FORM's OPTITEM pOIData - Pointer to the OIDATA structure Return Value: The form selected, a netavie number means error Author: 09-Dec-1993 Thu 14:35:59 created 06-Nov-1995 Mon 12:56:24 updated Re-write for the New UI Revision History: --*/ { LPWSTR pwSelName; POPTPARAM pOptParam; PFORM_INFO_1 pFI1; PFORMSRC pFS; ENUMFORMPARAM EFP; DWORD i; LONG Sel; DWORD cRollPaper; EXTRAINFO EI; if (!pOptItem) { return(1); } pwSelName = (LPWSTR)((pPI->Flags & PIF_DOCPROP) ? pPI->PlotDM.dm.dmFormName : pPI->CurPaper.Name); PLOTDBG(DBG_FORMS, ("Current Form: <%ws>", pwSelName)); EFP.pPlotDM = &(pPI->PlotDM); EFP.pPlotGPC = pPI->pPlotGPC; if (!PlotEnumForms(pPI->hPrinter, NULL, &EFP)) { PLOTERR(("CreateFormOI: PlotEnumForms() failed")); return(0); } cRollPaper = 0; if ((!(pPI->Flags & PIF_DOCPROP)) && (pPI->pPlotGPC->Flags & PLOTF_ROLLFEED)) { // // Add device' roll paper to the combo box too. // PLOTDBG(DBG_FORMS, ("Device support ROLLFEED so add RollPaper if any")); for (i= 0, pFS = (PFORMSRC)pPI->pPlotGPC->Forms.pData; i < (DWORD)pPI->pPlotGPC->Forms.Count; i++, pFS++) { if (!pFS->Size.cy) { ++cRollPaper; } } } PLOTDBG(DBG_FORMS, ("Valid Count is %ld [%ld + %ld] out of %ld", EFP.ValidCount + cRollPaper, EFP.ValidCount, cRollPaper, EFP.Count)); EI.Size = (DWORD)(cRollPaper * (sizeof(WCHAR) * CCHFORMNAME)); if (!CreateOPTTYPE(pPI, pOptItem, pOIData, EFP.ValidCount + cRollPaper, &EI)) { LocalFree((HLOCAL)EFP.pFI1Base); return(0); } pPI->pFI1Base = EFP.pFI1Base; pOptItem->pOptType->Style = OTS_LBCB_SORT; pOptParam = pOptItem->pOptType->pOptParam; for (i = 0, Sel = 0, pFI1 = EFP.pFI1Base; i < EFP.Count; i++, pFI1++) { if (pFI1->Flags & FI1F_VALID_SIZE) { pOptParam->cbSize = sizeof(OPTPARAM); pOptParam->Style = (pPI->pPlotGPC->Flags & PLOTF_PAPERTRAY) ? FS_TRAYPAPER : 0; pOptParam->pData = pFI1->pName; pOptParam->IconID = (pFI1->Flags & FI1F_ENVELOPE) ? IDI_CPSUI_ENVELOPE : IDI_CPSUI_STD_FORM; pOptParam->lParam = (LONG)i; if (!lstrcmp(pwSelName, pOptParam->pData)) { pOptItem->Sel = Sel; } pOptParam++; Sel++; } } if (cRollPaper) { LPWSTR pwStr = (LPWSTR)EI.pData; size_t cchpwStr = EI.Size / sizeof(WCHAR); // // Add device' roll paper to the combo box too. // for (i = 0, pFS = (PFORMSRC)pPI->pPlotGPC->Forms.pData; i < (DWORD)pPI->pPlotGPC->Forms.Count; i++, pFS++) { if (!(pFS->Size.cy)) { // // Got one, we have to translated into the UNICODE first // pOptParam->cbSize = sizeof(OPTPARAM); pOptParam->Style = FS_ROLLPAPER; pOptParam->pData = (LPTSTR)pwStr; pwStr += CCHFORMNAME; cchpwStr -= CCHFORMNAME; pOptParam->IconID = IDI_ROLLPAPER; pOptParam->lParam = (LONG)i; str2Wstr(pOptParam->pData, cchpwStr, pFS->Name); if (!lstrcmp(pwSelName, pOptParam->pData)) { pOptItem->Sel = Sel; } pOptParam++; Sel++; } } } return(1); }
DWORD MergePLOTDM( HANDLE hPrinter, PPLOTGPC pPlotGPC, PPLOTDEVMODE pPlotDMFrom, PPLOTDEVMODE pPlotDMTo, PFORMSIZE pCurForm ) /*++ Routine Description: This function merge and validate the pPlotDMTo from pPlotDMFrom. The PlotDMOut must valid Arguments: hPrinter - Handle to the printer to be checked pPlotGPC - The plotter's GPC data loaded from the file pPlotDMFrom - pointer to the input PLOTDEVMODE data structure, if can be NULL pPlotDMTo - Pointer to the output PLOTDEVMODE data structure, if pPlotDMFrom is NULL then a default PLOTDEVMODE is returned pCurForm - Pointer to the FORMSIZE data structure which will be updated if the pointer is not NULL, the final result of the form size/imagable area selected by the user will be written to here. the form name will be in pPlotDM->dmFormName. Return Value: the return value is a DWORD dmField error code which specified dmFields are invalid (DM_xxxxx in wingdi.h) if the return value has any DM_INV_xxx bits set then it should raised an error to the user. if return value is 0 then function sucessful Author: 25-Oct-1994 Tue 13:32:18 created -by- Daniel Chou (danielc) Revision History: --*/ { PLOTDEVMODE PlotDMIn; ENUMFORMPARAM EFP; DWORD dmErrFields = 0; SIZEL PaperSize; // // First: set the default PLOTDEVMODE for the output then from there // validate/settting from input devmode, if pwDeviceName passed as // NULL then it assume that pPlotDMTo alreay set and validated // // If we have invalid input devmode then this it is // if ((!pPlotDMFrom) || (!pPlotDMTo) || (!pPlotGPC)) { return(0); } // // Do some conversion here if necessary, first, copy the output one // CopyMemory(&PlotDMIn, pPlotDMTo, sizeof(PLOTDEVMODE)); ConvertDevmode((PDEVMODE) pPlotDMFrom, (PDEVMODE) &PlotDMIn); PLOTDBG(DBG_SHOWDEVMODE, ("--------------- Input DEVMODE Setting -------------------")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmDeviceName = %ls", (DWORD)PlotDMIn.dm.dmDeviceName)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmSpecVersion = %04lx", (DWORD)PlotDMIn.dm.dmSpecVersion)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmDriverVersion = %04lx", (DWORD)PlotDMIn.dm.dmDriverVersion)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmSize = %0ld (%ld)", (DWORD)PlotDMIn.dm.dmSize, sizeof(DEVMODE))); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmDriverExtra = %ld (%ld)", (DWORD)PlotDMIn.dm.dmDriverExtra, PLOTDM_PRIV_SIZE)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmFields = %08lx", (DWORD)PlotDMIn.dm.dmFields)); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmOrientation = %ld (%hs)", (DWORD)PlotDMIn.dm.dmOrientation, (PlotDMIn.dm.dmFields & DM_ORIENTATION) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmPaperSize = %ld (%hs)", (DWORD)PlotDMIn.dm.dmPaperSize, (PlotDMIn.dm.dmFields & DM_PAPERSIZE) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmPaperLength = %ld (%hs)", (DWORD)PlotDMIn.dm.dmPaperLength, (PlotDMIn.dm.dmFields & DM_PAPERLENGTH) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmPaperWidth = %ld (%hs)", (DWORD)PlotDMIn.dm.dmPaperWidth, (PlotDMIn.dm.dmFields & DM_PAPERWIDTH) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmScale = %ld (%hs)", (DWORD)PlotDMIn.dm.dmScale, (PlotDMIn.dm.dmFields & DM_SCALE) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmCopies = %ld (%hs)", (DWORD)PlotDMIn.dm.dmCopies, (PlotDMIn.dm.dmFields & DM_COPIES) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmPrintQuality = %ld (%hs)", (DWORD)PlotDMIn.dm.dmPrintQuality, (PlotDMIn.dm.dmFields & DM_PRINTQUALITY) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmColor = %ld (%hs)", (DWORD)PlotDMIn.dm.dmColor, (PlotDMIn.dm.dmFields & DM_COLOR) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: dmFormName = %ls (%hs)", (DWORD)PlotDMIn.dm.dmFormName, (PlotDMIn.dm.dmFields & DM_FORMNAME) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: Fill Truetype Font = %hs", (PlotDMIn.Flags & PDMF_FILL_TRUETYPE) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("ValidateSetPLOTDM: Plot On the Fly = %hs", (PlotDMIn.Flags & PDMF_PLOT_ON_THE_FLY) ? "ON" : "OFF")); PLOTDBG(DBG_SHOWDEVMODE, ("---------------------------------------------------------")); // // Statring checking the dmFields, *** REMEMBER: The orientation must // check before the checking the paper/form // if (PlotDMIn.dm.dmFields & DM_ORIENTATION) { switch (PlotDMIn.dm.dmOrientation) { case DMORIENT_PORTRAIT: case DMORIENT_LANDSCAPE: pPlotDMTo->dm.dmOrientation = PlotDMIn.dm.dmOrientation; pPlotDMTo->dm.dmFields |= DM_ORIENTATION; break; default: PLOTERR(("ValidatePLOTDM: Invalid dmOrientation = %ld", (LONG)PlotDMIn.dm.dmOrientation)); dmErrFields |= DM_ORIENTATION; break; } } // // Validate form name so we have correct data, assume error first // dmErrFields |= (DWORD)(PlotDMIn.dm.dmFields & DM_PAPER_FIELDS); if (((PlotDMIn.dm.dmFields & DM_PAPER_CUSTOM) == DM_PAPER_CUSTOM) && ((PlotDMIn.dm.dmPaperSize == DMPAPER_USER) || (PlotDMIn.dm.dmPaperSize == 0)) && (PaperSize.cx = DMTOSPL(PlotDMIn.dm.dmPaperWidth)) && (PaperSize.cy = DMTOSPL(PlotDMIn.dm.dmPaperLength)) && (PaperSize.cx >= MIN_SPL_FORM_CX) && (PaperSize.cy >= MIN_SPL_FORM_CY) && (((PaperSize.cx <= pPlotGPC->DeviceSize.cx) && (PaperSize.cy <= pPlotGPC->DeviceSize.cy)) || ((PaperSize.cy <= pPlotGPC->DeviceSize.cx) && (PaperSize.cx <= pPlotGPC->DeviceSize.cy)))) { // // First choice, this is what the caller wants, we need to validate // for this device, since the size may be larger then device can // handle // pPlotDMTo->dm.dmPaperWidth = PlotDMIn.dm.dmPaperWidth; pPlotDMTo->dm.dmPaperLength = PlotDMIn.dm.dmPaperLength; pPlotDMTo->dm.dmFields &= ~DM_PAPER_FIELDS; pPlotDMTo->dm.dmFields |= DM_PAPER_CUSTOM; pPlotDMTo->dm.dmPaperSize = DMPAPER_USER; pPlotDMTo->dm.dmFormName[0] = L'\0'; if (pCurForm) { // // This one is full imageable area as the widht/height // pCurForm->ImageArea.left = pCurForm->ImageArea.top = 0; pCurForm->Size.cx = pCurForm->ImageArea.right = PaperSize.cx; pCurForm->Size.cy = pCurForm->ImageArea.bottom = PaperSize.cy; } dmErrFields &= ~DM_PAPER_FIELDS; // Fine, no error PLOTDBG(DBG_CURFORM,("ValidateSetPLOTDM: FORM=USER <%ld> (%ld x %ld)", PlotDMIn.dm.dmPaperSize, PaperSize.cx, PaperSize.cy)); } else if ((PlotDMIn.dm.dmFields & (DM_PAPERSIZE | DM_FORMNAME)) && (EFP.pPlotDM = pPlotDMTo) && (EFP.pPlotGPC = pPlotGPC) && (PlotEnumForms(hPrinter, NULL, &EFP))) { FORM_INFO_1 *pFI1; SHORT PaperSize; BOOL Found = FALSE; // // Firstable check PaperSize index and if not found then check formname // if ((PlotDMIn.dm.dmFields & DM_PAPERSIZE) && ((PaperSize = PlotDMIn.dm.dmPaperSize) >= DMPAPER_FIRST) && (PaperSize <= (SHORT)EFP.Count) && (pFI1 = EFP.pFI1Base + (PaperSize - DMPAPER_FIRST)) && (pFI1->Flags & FI1F_VALID_SIZE)) { // // Whu..., this guy really pick a right index // Found = TRUE; PLOTDBG(DBG_CURFORM,("ValidateSetPLOTDM: Fount dmPaperSize=%ld", PlotDMIn.dm.dmPaperSize)); } else if (PlotDMIn.dm.dmFields & DM_FORMNAME) { // // Now go through all the formname trouble // pFI1 = EFP.pFI1Base; PaperSize = DMPAPER_FIRST; while (EFP.Count--) { if ((pFI1->Flags & FI1F_VALID_SIZE) && (!wcscmp(pFI1->pName, PlotDMIn.dm.dmFormName))) { PLOTDBG(DBG_CURFORM,("ValidateSetPLOTDM: Found dmFormName=%s", PlotDMIn.dm.dmFormName)); Found = TRUE; break; } ++PaperSize; ++pFI1; } } if (Found) { pPlotDMTo->dm.dmFields &= ~DM_PAPER_FIELDS; pPlotDMTo->dm.dmFields |= (DM_FORMNAME | DM_PAPERSIZE); pPlotDMTo->dm.dmPaperSize = PaperSize; pPlotDMTo->dm.dmPaperWidth = SPLTODM(pFI1->Size.cx); pPlotDMTo->dm.dmPaperLength = SPLTODM(pFI1->Size.cy); WCPYFIELDNAME(pPlotDMTo->dm.dmFormName, pFI1->pName); PLOTDBG(DBG_CURFORM,("FI1 [%ld]: (%ld x %ld), (%ld, %ld)-(%ld, %ld)", (LONG)pPlotDMTo->dm.dmPaperSize, pFI1->Size.cx, pFI1->Size.cy, pFI1->ImageableArea.left, pFI1->ImageableArea.top, pFI1->ImageableArea.right, pFI1->ImageableArea.bottom)); if (pCurForm) { pCurForm->Size = pFI1->Size; pCurForm->ImageArea = pFI1->ImageableArea; } dmErrFields &= ~DM_PAPER_FIELDS; // Fine, no error } // // Free up the memory used // LocalFree((HLOCAL)EFP.pFI1Base); } if ((PlotDMIn.dm.dmFields & DM_SCALE) && (pPlotGPC->MaxScale)) { if ((PlotDMIn.dm.dmScale > 0) && ((WORD)PlotDMIn.dm.dmScale <= pPlotGPC->MaxScale)) { pPlotDMTo->dm.dmScale = PlotDMIn.dm.dmScale; pPlotDMTo->dm.dmFields |= DM_SCALE; } else { PLOTERR(("ValidatePLOTDM: Invalid dmScale = %ld [%ld]", (LONG)PlotDMIn.dm.dmScale, (LONG)pPlotGPC->MaxScale)); dmErrFields |= DM_SCALE; } } if ((PlotDMIn.dm.dmFields & DM_COPIES) && (pPlotGPC->MaxCopies > 1)) { if ((PlotDMIn.dm.dmCopies > 0) && ((WORD)PlotDMIn.dm.dmCopies <= pPlotGPC->MaxCopies)) { pPlotDMTo->dm.dmCopies = PlotDMIn.dm.dmCopies; pPlotDMTo->dm.dmFields |= DM_COPIES; } else { PLOTERR(("ValidatePLOTDM: Invalid dmCopies = %ld [%ld]", (LONG)PlotDMIn.dm.dmCopies, (LONG)pPlotGPC->MaxCopies)); dmErrFields |= DM_COPIES; } } if (PlotDMIn.dm.dmFields & DM_PRINTQUALITY) { dmErrFields |= DM_PRINTQUALITY; // assume error, proven otherwise if (pPlotGPC->MaxQuality) { switch (PlotDMIn.dm.dmPrintQuality) { case DMRES_DRAFT: case DMRES_LOW: case DMRES_MEDIUM: case DMRES_HIGH: dmErrFields &= ~DM_PRINTQUALITY; pPlotDMTo->dm.dmPrintQuality = PlotDMIn.dm.dmPrintQuality; pPlotDMTo->dm.dmFields |= DM_PRINTQUALITY; break; } } if (dmErrFields & DM_PRINTQUALITY) { PLOTERR(("ValidatePLOTDM: Invalid dmPrintQuality = %ld [%ld]", (LONG)PlotDMIn.dm.dmPrintQuality, (LONG)pPlotGPC->MaxQuality)); } } if (PlotDMIn.dm.dmFields & DM_COLOR) { dmErrFields |= DM_COLOR; // assume error, proven otherwise if (pPlotGPC->Flags & PLOTF_COLOR) { switch (PlotDMIn.dm.dmColor) { case DMCOLOR_MONOCHROME: if (!(pPlotGPC->Flags & PLOTF_RASTER)) { PLOTERR(("ValidatePLOTDM: Cannot Set Pen Plotter to MONO")); break; } case DMCOLOR_COLOR: pPlotDMTo->dm.dmColor = PlotDMIn.dm.dmColor; pPlotDMTo->dm.dmFields |= DM_COLOR; dmErrFields &= ~DM_COLOR; break; } } else if (PlotDMIn.dm.dmColor == DMCOLOR_MONOCHROME) { dmErrFields &= ~DM_COLOR; } if (dmErrFields & DM_COLOR) { PLOTERR(("ValidatePLOTDM: Invalid dmColor = %ld [%hs]", (LONG)PlotDMIn.dm.dmColor, (pPlotGPC->Flags & PLOTF_COLOR) ? "COLOR" : "MONO")); } } // // Any other dmFields we just skip because we do not have that caps, now // check if they have correct EXTDEVMODE stuff // if ((PlotDMIn.dm.dmDriverExtra == PLOTDM_PRIV_SIZE) && (PlotDMIn.PrivID == PLOTDM_PRIV_ID) && (PlotDMIn.PrivVer == PLOTDM_PRIV_VER)) { pPlotDMTo->Flags = (DWORD)(PlotDMIn.Flags & PDMF_ALL_BITS); pPlotDMTo->ca = PlotDMIn.ca; if (pPlotGPC->Flags & PLOTF_RASTER) { pPlotDMTo->Flags |= PDMF_FILL_TRUETYPE; } else { // // Non raster device does not have plot on the fly mode // pPlotDMTo->Flags &= ~PDMF_PLOT_ON_THE_FLY; } if (!ValidateColorAdj(&(pPlotDMTo->ca))) { dmErrFields |= DM_INV_PLOTPRIVATE; PLOTERR(("ValidatePLOTDM: Invalid coloradjusment data")); } } return(dmErrFields); }