// Make a new ScreenRef that corresponds to the rectangle indicated by the where parameter ScreenRef NewScreenRef( const Rect *where, OSStatus *error ) { RLDisplay *display = NULL; // MakeNewRLDisplay may throw exceptions so we have to catch them here so // that we dont inflict them on our C loving public! try { display = MakeNewRLDisplay( where ); // In the particular case of operator new failing, we just get a NULL // pointer back, so generate the exception ourselves. if( ! display ) { DEBUGMESSAGE( "Screen Ref allocation failed -- not enough memory!" ); throw OSStatus( rlOutOfMemory ); } if( error ) *error = noErr; } catch( OSStatus err ) { if( error ) *error = err; } return ScreenRef( display ); }
OSStatus FadeToGamma( ScreenRef screen, const RLGammaTable *newGamma, float seconds ) { if( ! newGamma ) return paramErr; DEBUGMESSAGE( "Fading to new gamma over " << seconds << " seconds." ); //Calculate the starting and ending time for out fade double startTime = GetCurrentTime(); double endTime = startTime + seconds; //Determine our starting gamma RLGammaTable oldGamma, currentGamma; OSStatus error = GetGamma( screen, &oldGamma ); if( error ) return error; //Loop until we run out of time, resetting the gamma as fast as possible for( double currentTime = GetCurrentTime(); currentTime < endTime && ! error; currentTime = GetCurrentTime() ) { //The fraction is the percentage of time that we have spend so far in this loop as a value between 0 and 1.0 double fraction = (currentTime - startTime) / seconds; //Calculate the new gamma based on the amount of time spent so far //(1-fraction)startGamma + fraction * endGamma = startGamma + fraction( endGamma - startGamma) for( int i = 0; i < kGammaTableEntryCount; i++ ) { currentGamma.red[i] = oldGamma.red[i] + fraction * (newGamma->red[i] - oldGamma.red[i]); currentGamma.green[i] = oldGamma.green[i] + fraction * (newGamma->green[i] - oldGamma.green[i]); currentGamma.blue[i] = oldGamma.blue[i] + fraction * (newGamma->blue[i] - oldGamma.blue[i]); } error = SetGamma( screen, ¤tGamma ); } if( error ) DEBUGMESSAGE( "Got error # " << error << " doing a gamma fade in FadeToGamma(). Attempting to achieve the final gamma...." ); return SetGamma( screen, newGamma ); }
// MT : this is a compatibility routine to do stuff that used to be done in the cfm initialiser of rezlib static Handle LoadDITL() { //Load the dialog item list for our AskIfNewResolutionWorks() function dialog box static Handle s_ditl=NULL; if (!s_ditl) { //Load our DITL s_ditl = Get1Resource( 'DITL', 27398 ); if( s_ditl ) { DEBUGMESSAGE( "\"AskIfNewResolutionWorks\" DITL loaded." ); DetachResource( s_ditl ); } else DEBUGMESSAGE( "Error: Failed to load DITL." ); OSStatus err = ResError(); CHECKERR( err ); if( err ) DEBUGMESSAGE( "Found Resource Manager error # " << err << " after attempting to load the \"AskIfNewResolutionWorks\" DITL. " ); } return s_ditl; }
//Dispose of a retrace callback installed using InstallVerticalRetraceProcedure(). void DisposeVerticalRetraceProcedure( RetraceToken token ) { RetraceProc *proc = (RetraceProc*) token; if( NULL == proc ) return; RLDisplay *owner = proc->GetOwner(); if( NULL == owner ) { DEBUGMESSAGE("Error: detected a retrace procedure without an owner!" ); return; } owner->DisposeVerticalRetraceProcedure( proc ); }
// Poll the display for its current resolution, color depth and other settings OSStatus GetCurrentSetting( ScreenRef screen, RLInfo *info ) { RLDisplay *display = (RLDisplay *) screen; if( ! display ) return rlInvalidScreenRef; if( NULL == info ) return paramErr; if( info->rlInfoType != 0 ) { DEBUGMESSAGE("Be sure to set the RLInfo.rlInfoType field to zero before calling GetCurrentSetting()!" ); return paramErr; } return display->GetCurrentScreenSetting( info ); }
static BOOL CALLBACK AboutDlgProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { //DEBUGMESSAGE(("AboutDlgProc")); switch (message) { case WM_INITDIALOG: { DEBUGMESSAGE(("AboutDlgProc - WM_INITDIALOG")); LPPROPSHEETPAGE page = (LPPROPSHEETPAGE ) lParam; // attach to our property sheet page an instance of our data holder class CHyperLink *hyperLink = new CHyperLink(); SetWindowLongPtr(hDlg, DWL_USER, (LONG) hyperLink); // transform the static text into an hyperlink! // it couldn't be easier - many thanks to Olivier Langlois hyperLink->ConvertStaticToHyperlink( hDlg, IDC_PROJECT_URL, TEXT("http://emfprinter.sourceforge.net")); // set about text TCHAR txt[256]; StringCchPrintf(txt, 256, TEXT("This is EmfPrinter %d.%d.%d by Francesco Montorsi (c) 2007.\n") TEXT("Licensed under the terms of the GNU General Public License."), emfVERSION_MAJOR, emfVERSION_MINOR, emfVERSION_RELEASE); HWND hwnd = GetDlgItem(hDlg, IDC_ABOUT_TEXT); SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)txt); } break; default: //DEBUGMESSAGE(("AboutDlgProc - unhandled message %d", message)); return FALSE; } return TRUE; }
// DrvDocumentPropertySheets function is responsible for creating property // sheet pages that describe a print document's properties. LONG DrvDocumentPropertySheets( PPROPSHEETUI_INFO pPSUIInfo, LPARAM lParam ) { //DEBUGMESSAGE(("DrvDocumentPropertySheets")); LONG lRetValue = -1; if (pPSUIInfo == NULL) return DirectDrvDocumentPropertySheets((PDOCUMENTPROPERTYHEADER) lParam); else if (pPSUIInfo->lParamInit != 0) return IndirectDrvDocumentPropertySheets(pPSUIInfo, (PDOCUMENTPROPERTYHEADER)pPSUIInfo->lParamInit, lParam); else DEBUGMESSAGE(("Received a NULL PDOCUMENTPROPERTYHEADER")); return lRetValue; }
int pvs_parse(unsigned char *buffer, unsigned int *len) { char *pos, *lastpos; unsigned int reslen; reslen=0; buffer[*len]=0; lastpos=(char*)buffer; DEBUGMESSAGE(buffer); pos = strstr((char*)buffer, PVSPREFIX); while (pos) { char *t; int i; int savereslen; DEBUGMESSAGE(pos); /* copy plain content */ savereslen=reslen; if (pvs_after_init) { while (lastpos<pos) { buffer[reslen++] = *lastpos++; } } if (pvs_in_checker) { unsigned char cv; int nres; nres = reslen-savereslen; if (nres) { cv = buffer[reslen]; buffer[reslen]=0; pvs_parse_prove(buffer+savereslen, &nres); buffer[reslen]=cv; reslen=savereslen+nres; } } i=0; while (pvsmessage[i].keyval && strncmp(pos+PVSPREFLEN,pvsmessage[i].keyval,pvsmessage[i].keylen)) i++; if (!pvsmessage[i].keyval) { /* unknown pvs message */ char *b; i++; b=pos+PVSPREFLEN; while (*b!=' ') b++; *b=0; strcpy(pvsmessage[i].keyval,pos+PVSPREFLEN); pvsmessage[i].keylen = strlen(pos+PVSPREFLEN); sprintf(pvsmessage[i].endstr, PVSENDPREF "%s\n", pos+PVSPREFLEN); pvsmessage[i].endlen = strlen(pvsmessage[i].endstr); } t=strstr(pos, pvsmessage[i].endstr); if (t) { *t=0; (*pvsmessage[i].func)(pos+PVSPREFLEN+pvsmessage[i].keylen); t=t+pvsmessage[i].endlen; } else { int k; parsemess=i; k=strlen(pos); if (k) { if (stilllen<k) { if (stilltoparse) stilltoparse = realloc(stilltoparse, (k+1)*sizeof(char)); else stilltoparse = malloc((k+1)*sizeof(char)); stilllen=k; } strcpy(stilltoparse, pos); t=pos+k; } } lastpos=t; pos=strstr(lastpos,PVSPREFIX); } { int savereslen; savereslen=reslen; if (pvs_after_init) { while (*lastpos) { buffer[reslen++]=*lastpos++; } } buffer[reslen]=0; DEBUGMESSAGE(buffer); if (strstr(buffer, "(Yes or No)")) { edit_string_to_proces(translate("no\n"), translate("PVS-shell")); } if (pvs_before_realtime && strstr(buffer, "Real time =")) { pvs_before_realtime=0; pvs_start_proof(NULL); } if (pvs_in_checker) { int nres; nres = reslen-savereslen; if (nres) { pvs_parse_prove(buffer,&nres); reslen=savereslen+nres; } } DEBUGMESSAGE(buffer); } message(MP_MESSAGE,busylist[currentbusy]); currentbusy=(currentbusy+1)%4; *len=reslen; return (reslen==0); }
// DrvDeviceCapabilities function returns requested information // about a printer's capabilities. // // NOTE: // WE NEED TO TAKE INTO ACCOUNT DIFFERENCE BETWEEN OUR CAPS, TARGET CAPS DWORD DrvDeviceCapabilities( HANDLE hPrinter, PWSTR pDeviceName, WORD iDevCap, VOID *pvOutput, PDEVMODE pDevMode ) { //DEBUGMESSAGE(("DrvDeviceCapabilities")); DWORD dwRetValue = GDI_ERROR; WORD *pwOutput = (WORD*)pvOutput; POINTS *pptsdwRet = ((POINTS *)&dwRetValue); switch (iDevCap) { case DC_PAPERNAMES: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_PAPERNAMES")); case DC_MEDIAREADY: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_MEDIAREADY")); if (pvOutput) { TCHAR str[] = TEXT("None (the printer is virtual!)"); // each paper name is 64 chars max strCopy((LPTSTR)pvOutput, str, strBufferSize(str)); } return 1; case DC_PAPERS: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_PAPERS")); if (pvOutput) *pwOutput = DMPAPER_A4; // A4 is 210x297 mm return 1; case DC_PAPERSIZE: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_PAPERSIZE")); if (pvOutput) { POINT *arr = (POINT*)pvOutput; arr[0].x = A4_WIDTH_MM*10; arr[0].y = A4_HEIGHT_MM*10; } return 1; case DC_BINNAMES: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_BINNAMES")); if (pvOutput) // each bin name is 24 chars max strCopy((LPTSTR)pvOutput, TEXT("Bin"), 3*sizeof(TCHAR)); return 1; case DC_BINS: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_BINS")); if (pvOutput) *pwOutput = DMBIN_ONLYONE; return 1; case DC_COPIES: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_COPIES")); return 1; case DC_STAPLE: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_STAPLE")); return 0; // not supported case DC_COLLATE: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_COLLATE")); return 0; // not supported case DC_DUPLEX: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_DUPLEX")); return 0; // not supported case DC_ENUMRESOLUTIONS: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_ENUMRESOLUTIONS")); if (pvOutput) { LONG *arr = (LONG*)pvOutput; arr[0] = emfDRIVER_WIDTH_DPI; arr[1] = emfDRIVER_HEIGHT_DPI; } return 1; // info about our driver's devmode case DC_DRIVER: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_DRIVER")); return emfDRIVER_REAL_VERSION; case DC_EXTRA: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_EXTRA")); return extdmSizeofPrivate(); case DC_SIZE: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_SIZE")); return sizeof(DEVMODEW); // size of only public members case DC_VERSION: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_VERSION")); return DM_SPECVERSION; case DC_FIELDS: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_FIELDS")); return extdmDEFAULT_FIELDS; case DC_FILEDEPENDENCIES: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_FILEDEPENDENCIES")); return 0; case DC_MAXEXTENT: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_MAXEXTENT")); pptsdwRet->x = A4_WIDTH_MM*10; pptsdwRet->y = A4_HEIGHT_MM*10; return dwRetValue; case DC_MINEXTENT: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_MINEXTENT")); // min is 1 mm pptsdwRet->x = 10; pptsdwRet->y = 10; return dwRetValue; case DC_ORIENTATION: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_ORIENTATION")); return 90; case DC_TRUETYPE: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_TRUETYPE")); return DCTT_BITMAP;//|DCTT_SUBDEV|DCTT_DOWNLOAD; case DC_PERSONALITY: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_PERSONALITY")); if (pvOutput) // each printer desc lang name is 32 chars max strCopy((LPTSTR)pvOutput, TEXT("EMF"), 3*sizeof(TCHAR)); return 1; case DC_COLORDEVICE: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_COLORDEVICE")); return 1; //case DC_SPL_MEDIAREADY: case DC_NUP: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_NUP")); return 1; case DC_PRINTERMEM: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_PRINTERMEM")); return 4096; // simulate 4MB of internal mem // 60 pages per minute: we're fast :) case DC_PRINTRATE: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_PRINTRATE")); case DC_PRINTRATEPPM: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_PRINTRATEPPM")); return 60; case DC_PRINTRATEUNIT: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_PRINTRATEUNIT")); return PRINTRATEUNIT_PPM; case DC_BINADJUST: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_BINADJUST")); // should be not used for WinXP/2000 but I've tested // that MS Word calls WinXP drivers with this code too! return DCBA_FACEUPNONE; case DC_EMF_COMPLIANT: DEBUGMESSAGE(("DrvDeviceCapabilities - DC_EMF_COMPLIANT")); // should be not used for WinXP/2000 but just to be sure... return 1; // other win98 only codes: //case DC_DATATYPE_PRODUCED: //case DC_MANUFACTURER: //case DC_MODEL: default: DEBUGMESSAGE(("Unexpected device capability required: %d", iDevCap)); return GDI_ERROR; } return dwRetValue; }
static BOOL CALLBACK DocPropDlgProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { //DEBUGMESSAGE(("DocPropDlgProc")); switch (message) { case WM_INITDIALOG: { DEBUGMESSAGE(("DocPropDlgProc - WM_INITDIALOG")); LPPROPSHEETPAGE page = (LPPROPSHEETPAGE) lParam; // attach to our property sheet page an instance of our data holder class DocumentPropDialogData *data = (DocumentPropDialogData *) page->lParam; SetWindowLongPtr(hDlg, DWL_USER, (LONG) data); // fill output format combos HWND hwndVectorFormats = GetDlgItem(hDlg, IDC_COMBO_VECTOR_FORMAT); FillComboWithOutputFormats(hwndVectorFormats, g_vectorFormats, ARRCOUNT(g_vectorFormats)); HWND hwndRasterFormats = GetDlgItem(hDlg, IDC_COMBO_RASTER_FORMAT); FillComboWithOutputFormats(hwndRasterFormats, g_rasterFormats, ARRCOUNT(g_rasterFormats)); // select the right format SelectFormat(hDlg, extdmGetOutputFormat(data->m_pExtdmCurrent)); // set default text control contents SendMessage(GetDlgItem(hDlg, IDC_OUTPUT_FOLDER), WM_SETTEXT, 0, (LPARAM)extdmGetOutputFolder(data->m_pExtdmCurrent)); SendMessage(GetDlgItem(hDlg, IDC_OUTPUT_FILENAME), WM_SETTEXT, 0, (LPARAM)extdmGetOutputFilename(data->m_pExtdmCurrent)); SendMessage(GetDlgItem(hDlg, IDC_IMAGEMAGICK_OPTIONS), WM_SETTEXT, 0, (LPARAM)extdmGetConvertOptions(data->m_pExtdmCurrent)); SendMessage(GetDlgItem(hDlg, IDC_POSTGEN_CMD), WM_SETTEXT, 0, (LPARAM)extdmGetPostGenCmd(data->m_pExtdmCurrent)); // check override box eventually CheckDlgButton(hDlg, IDC_OVERRIDE_CHECKBOX, extdmAllowUserOverride(data->m_pExtdmCurrent) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_CROP_CHECKBOX, extdmCropBorders(data->m_pExtdmCurrent) ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(hDlg, IDC_OPEN_VIEWER_CHECKBOX, extdmViewOutputFile(data->m_pExtdmCurrent) ? BST_CHECKED : BST_UNCHECKED); } break; // case WM_INITDIALOG case WM_COMMAND: return OnCommand(hDlg, LOWORD(wParam), HIWORD(wParam)); case WM_NOTIFY: return OnNotify(hDlg, (LPNMHDR)lParam); default: //DEBUGMESSAGE(("DocPropDlgProc - unhandled message %d", message)); return FALSE; } return TRUE; }
BOOL OnCommand(HWND hDlg, WORD wID, WORD code) { //DEBUGMESSAGE(("OnCommand")); DocumentPropDialogData *data = (DocumentPropDialogData *) GetWindowLongPtr(hDlg, DWL_USER); switch (wID) { case IDC_COMBO_VECTOR_FORMAT: case IDC_COMBO_RASTER_FORMAT: { DEBUGMESSAGE(("OnCommand - combo command")); switch (code) { case CBN_SELCHANGE: { DWORD nId = (wID==IDC_COMBO_VECTOR_FORMAT) ? IDC_VECTOR_FORMAT_RADIOBOX : IDC_RASTER_FORMAT_RADIOBOX; // select the radio button next to the combo which changed CheckRadioButton(hDlg, IDC_VECTOR_FORMAT_RADIOBOX, IDC_RASTER_FORMAT_RADIOBOX, nId); } break; default: break; } } break; case IDC_BROWSE_BUTTON: { BROWSEINFO bi; bi.hwndOwner = hDlg; bi.pidlRoot = NULL; bi.pszDisplayName = NULL; bi.lpszTitle = TEXT("Choose output folder"); bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; bi.lpfn = BrowseCallbackProc; LPTSTR folder = NULL; if (!GetEditControlText(&folder, GetDlgItem(hDlg, IDC_OUTPUT_FOLDER))) { DEBUGMESSAGE(("DocPropDlgProc - could not get output folder text")); return FALSE; } bi.lParam = (LPARAM)folder; // param for the callback const int verComCtl32 = GetComCtl32Version(); // we always add the edit box (it doesn't hurt anybody, does it?) if it is // supported by the system if ( verComCtl32 >= 471 ) { bi.ulFlags |= BIF_EDITBOX; } // to have the "New Folder" button we must use the "new" dialog style which // is also the only way to have a resizable dialog if (verComCtl32 >= 500) { bi.ulFlags |= BIF_NEWDIALOGSTYLE; } // do show the dialog wxItemIdList pidl(SHBrowseForFolder(&bi)); // cleanup wxItemIdList::Free((LPITEMIDLIST)bi.pidlRoot); strFree((LPTSTR)bi.lParam); if ( !pidl ) { DEBUGMESSAGE(("user hit cancel")); return TRUE; } LPTSTR newPath = pidl.GetPath(); if (newPath) { // change the text in the associated control SendMessage(GetDlgItem(hDlg, IDC_OUTPUT_FOLDER), WM_SETTEXT, 0, (LPARAM)newPath); strFree(newPath); } } break; default: break; } return FALSE; }
BOOL OnNotify(HWND hDlg, LPNMHDR lpNMHdr) { //DEBUGMESSAGE(("OnNotify")); UINT uiCode = lpNMHdr->code; switch (uiCode) { case PSN_APPLY: { DEBUGMESSAGE(("OnNotify - PSN_APPLY")); DocumentPropDialogData *data = (DocumentPropDialogData *) GetWindowLongPtr(hDlg, DWL_USER); if (data == NULL) { DEBUGMESSAGE(("DocPropDlgProc - invalid internal data pointer")); return FALSE; } // which format combo should we use? LPTSTR format = NULL; if (IsDlgButtonChecked(hDlg, IDC_VECTOR_FORMAT_RADIOBOX) == BST_CHECKED) { INT sel = GetComboCurSel(GetDlgItem(hDlg, IDC_COMBO_VECTOR_FORMAT)); format = strDuplicate(g_vectorFormats[sel].strName); } else if (IsDlgButtonChecked(hDlg, IDC_RASTER_FORMAT_RADIOBOX) == BST_CHECKED) { INT sel = GetComboCurSel(GetDlgItem(hDlg, IDC_COMBO_RASTER_FORMAT)); format = strDuplicate(g_rasterFormats[sel].strName); } else { DEBUGMESSAGE(("DocPropDlgProc - unexpected condition")); return FALSE; } // get the output folder & validate it LPTSTR folder = NULL; if (!GetEditControlText(&folder, GetDlgItem(hDlg, IDC_OUTPUT_FOLDER))) { DEBUGMESSAGE(("DocPropDlgProc - could not get output folder text")); return FALSE; } if (!FolderExists(folder)) { ErrorMessage(hDlg, TEXT("Warning"), TEXT("The given output directory does not exist!")); return FALSE; } // get the output filename & validate it LPTSTR filename = NULL; if (!GetEditControlText(&filename, GetDlgItem(hDlg, IDC_OUTPUT_FILENAME))) { DEBUGMESSAGE(("DocPropDlgProc - could not get output filename text")); return FALSE; } if (!IsValidFilename(filename)) { LPTSTR temp = strCat(TEXT("The given output filename is not valid!\n"), TEXT("It should not contain any of the '"), g_strFileNameForbiddenChars, TEXT("' characters."), NULL); ErrorMessage(hDlg, TEXT("Warning"), temp); strFree(temp); return FALSE; } // get the raster conv options LPTSTR rasteropt = NULL; if (!GetEditControlText(&rasteropt, GetDlgItem(hDlg, IDC_IMAGEMAGICK_OPTIONS))) { DEBUGMESSAGE(("DocPropDlgProc - could not get raster conv opt text")); return FALSE; } // get the postgen cmd LPTSTR postgen = NULL; if (!GetEditControlText(&postgen, GetDlgItem(hDlg, IDC_POSTGEN_CMD))) { DEBUGMESSAGE(("DocPropDlgProc - could not get postgen cmd text")); return FALSE; } // get override checkbox status BOOL override = IsDlgButtonChecked(hDlg, IDC_OVERRIDE_CHECKBOX) == BST_CHECKED; // get crop checkbox BOOL crop = IsDlgButtonChecked(hDlg, IDC_CROP_CHECKBOX) == BST_CHECKED; // get open-output checkbox BOOL openout = IsDlgButtonChecked(hDlg, IDC_OPEN_VIEWER_CHECKBOX) == BST_CHECKED; // save all data in the EXTDEVMODE extdmSetPrivateData(data->m_pExtdmCurrent, format, filename, folder, rasteropt, postgen, override, openout, crop); // cleanup strFree(format); strFree(filename); strFree(folder); strFree(postgen); strFree(rasteropt); // call the _SET_RESULT callback PFNCOMPROPSHEET pfnComPropSheet = data->m_pfnComPropSheet; LONG lTemp = pfnComPropSheet( data->m_hComPropSheet, CPSFUNC_SET_RESULT, (LPARAM) data->m_hPropSheetAdded, CPSUI_OK ); return TRUE; } break; case PSN_RESET: break; case PSN_SETACTIVE: break; default: break; } return FALSE; }
LONG IndirectDrvDocumentPropertySheets(PPROPSHEETUI_INFO pPSUIInfo, PDOCUMENTPROPERTYHEADER pdph, LPARAM lParam) { //DEBUGMESSAGE(("IndirectDrvDocumentPropertySheets - indirect call by the UI")); DWORD fMode = pdph->fMode; ASSERT(pdph != NULL && pPSUIInfo != NULL); if (fMode & DM_ADVANCED) { // MSDN say: // If set, the DrvDocumentPropertySheets function should only // create the Advanced document page. // If not set, the DrvDocumentPropertySheets function should // create both the Page Setup and Advanced document pages. } // WE ARE BEING CALLED BY CPSUI, TO SHOW TO THE USER // THE CONFIGURABLE PROPERTY SHEETS FOR THIS DOCUMENT switch (pPSUIInfo->Reason) { case PROPSHEETUI_REASON_INIT: { DEBUGMESSAGE(("IndirectDrvDocumentPropertySheets - initializing the sheet")); // alloc data DocumentPropDialogData *data = new DocumentPropDialogData(); LPPROPSHEETPAGE page = (LPPROPSHEETPAGE) malloc(sizeof(PROPSHEETPAGE)); if (data == NULL || page == NULL) { DEBUGMESSAGE(("OUT OF MEMORY")); return -1; // failure } // initialize a page of the document property dialog ZeroMemory(page, sizeof(*page)); page->dwSize = sizeof(*page); page->hInstance = g_hInstDLL; page->pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_DOCUMENTPROPERTIES); page->lParam = (LPARAM) data; page->pfnDlgProc = (DLGPROC) DocPropDlgProc; // from pm //page->dwFlags = PSP_USECALLBACK; //psp->pfnCallback = PropSheetPageProc; // save some stuff in the provided pointer pPSUIInfo->UserData = (ULONG_PTR) page; pPSUIInfo->Result = CPSUI_CANCEL; // fill DocumentPropDialogData structure // ------------------------------------- data->m_bAllowUserUpdate = (pdph->fMode & DM_OUT_BUFFER) && !(pdph->fMode & DM_NOPERMISSION) && pdph->pdmOut != NULL; // set the initial devmode for this dialog if ((pdph->fMode & DM_IN_BUFFER) && pdph->pdmIn != NULL && extdmIsAnExtDevMode(pdph->pdmIn)) dmCopy((LPBYTE)data->m_pExtdmCurrent, pdph->pdmIn); else extdmSetToDefault(data->m_pExtdmCurrent); data->m_pfnComPropSheet = pPSUIInfo->pfnComPropSheet; data->m_hComPropSheet = pPSUIInfo->hComPropSheet; // this call will actually create the sheet data->m_hPropSheetAdded = (HANDLE) pPSUIInfo->pfnComPropSheet( pPSUIInfo->hComPropSheet, CPSFUNC_ADD_PROPSHEETPAGE, (LPARAM)page, 0 ); if (data->m_hPropSheetAdded == NULL) { DEBUGMESSAGE(("COULD NOT CREATE THE PROPERTY SHEET PAGE")); delete data; if (page != NULL) free(page); return -1; } // create the about sheet { LPPROPSHEETPAGE page = (LPPROPSHEETPAGE) malloc(sizeof(PROPSHEETPAGE)); if (data == NULL || page == NULL) { DEBUGMESSAGE(("OUT OF MEMORY")); return -1; // failure } // initialize a page of the document property dialog ZeroMemory(page, sizeof(*page)); page->dwSize = sizeof(*page); page->hInstance = g_hInstDLL; page->pszTemplate = MAKEINTRESOURCE(IDD_DIALOG_ABOUT); page->lParam = (LPARAM) data; page->pfnDlgProc = (DLGPROC) AboutDlgProc; // ignore error code - it's not fundamental (HANDLE) pPSUIInfo->pfnComPropSheet( pPSUIInfo->hComPropSheet, CPSFUNC_ADD_PROPSHEETPAGE, (LPARAM)page, 0 ); } return 1; // success } break; case PROPSHEETUI_REASON_SET_RESULT: { DEBUGMESSAGE(("IndirectDrvDocumentPropertySheets - saving the result")); LPPROPSHEETPAGE page = (LPPROPSHEETPAGE) pPSUIInfo->UserData; PSETRESULT_INFO psri = (PSETRESULT_INFO) lParam; if (psri->Result != CPSUI_OK) return 1; if (page == NULL) { DEBUGMESSAGE(("Unexpected NULL ptr")); return -1; } DocumentPropDialogData* data = (DocumentPropDialogData *) page->lParam; if (data->m_bAllowUserUpdate) { // save the user-edited options in the given out PDEVMODE dmCopy((LPBYTE)pdph->pdmOut, (PCDEVMODE)data->m_pExtdmCurrent); } return 1; } break; case PROPSHEETUI_REASON_DESTROY: { DEBUGMESSAGE(("IndirectDrvDocumentPropertySheets - destroying the sheet")); LPPROPSHEETPAGE page = (LPPROPSHEETPAGE) pPSUIInfo->UserData; if (page == NULL) { DEBUGMESSAGE(("Unexpected NULL ptr")); return -1; } DocumentPropDialogData *data = (DocumentPropDialogData *) page->lParam; if (data != NULL) delete data; // we won't need it anymore else DEBUGMESSAGE(("Unexpected NULL ptr")); free(page); pPSUIInfo->UserData = 0; return 1; } break; default: break; } DEBUGMESSAGE(("IndirectDrvDocumentPropertySheets - unhandled reason %d", pPSUIInfo->Reason)); return -1; // unhandled reason... }
LONG DirectDrvDocumentPropertySheets(PDOCUMENTPROPERTYHEADER pdph) { //DEBUGMESSAGE(("DirectDrvDocumentPropertySheets - direct call by the spooler")); // CALLED DIRECTLY BY SPOOLER, RATHER THAN INDIRECTLY THROUGH CPSUI DWORD fMode = pdph->fMode; ASSERT(pdph != NULL); if (fMode == 0 || pdph->pdmOut == NULL) { DEBUGMESSAGE(("DirectDrvDocumentPropertySheets - " "I was asked for EXTDEVMODE size (which is %d bytes)", extdmSizeof())); pdph->cbOut = (LONG) extdmSizeof(); return pdph->cbOut; } PDEVMODE pdmIn = pdph->pdmIn; PDEVMODE pdmOut = pdph->pdmOut; if (pdmIn && (fMode & DM_IN_BUFFER) && pdmIn->dmSize == sizeof(DEVMODEW) && pdmIn->dmDriverExtra == extdmSizeofPrivate()) { // MSDN says: // The caller has supplied a DEVMODE structure pointer // in pdmIn, and the DrvDocumentPropertySheets function // should update its internal DEVMODE structure to reflect // the contents of the supplied DEVMODE. DEBUGMESSAGE(("DirectDrvDocumentPropertySheets - I was asked to " "update my internal DEVMODE from pdmIn")); // nothing to update actually return 1; // success } if (pdmOut && (fMode & DM_OUT_BUFFER)) { // MSDN says: // The caller has supplied a DEVMODE structure pointer in // pdmOut, and the DrvDocumentPropertySheets function // should copy the contents of its internal DEVMODE structure // into the supplied DEVMODE. DEBUGMESSAGE(("DirectDrvDocumentPropertySheets - I was asked to " "update pdmOut from my internal DEVMODE")); // create our internal devmode PEXTDEVMODE pExt = (PEXTDEVMODE)pdmOut; extdmSetToDefault(pExt); // get the devmode for current printer PDEVMODE pdmTemp = GetPrinterDevMode(pdph->pszPrinterName); if (pdmTemp != NULL) { extdmMerge(pExt, pdmTemp); free(pdmTemp); } // copy our "internal" devmode in the output devmode dmCopy((LPBYTE) pdmOut, (PDEVMODE) pExt); return 1; // success } if ((fMode & DM_ADVANCED) || (fMode & DM_IN_PROMPT)) { // we were asked to create document property sheets in a // direct spooler call - this shouldn't happen! DEBUGMESSAGE(("DirectDrvDocumentPropertySheets - I was asked to create " "sheets in a direct call - WARNING THIS SHOULDN'T HAPPEN")); return -1; } if ((fMode & DM_USER_DEFAULT) || (fMode & DM_OUT_DEFAULT)) { DEBUGMESSAGE(("DirectDrvDocumentPropertySheets - DM_USER_DEFAULT and " "DM_OUT_DEFAULT should not be used!")); return -1; } DEBUGMESSAGE(("DirectDrvDocumentPropertySheets - unhandled call with " "fMode == %d, pdmIn == %d, pdmOut == %d", fMode, pdmIn, pdmOut)); return -1; }
/* Do a gamma fade to the gamma table provided over the time period desired */ OSStatus FadeToGammaMultiple( ScreenRef *screen, unsigned int count, const RLGammaTable *newGamma, float seconds ) { int i; OSStatus error = noErr; if( ! newGamma ) return paramErr; //Calculate the starting and ending time for out fade double startTime = GetCurrentTime(); double endTime = startTime + seconds; //Determine our starting gamma RLGammaTable *oldGamma = (RLGammaTable*) NewPtr( sizeof( RLGammaTable ) * count ); RLGammaTable *currentGamma = (RLGammaTable*) NewPtr( sizeof( RLGammaTable ) * count ); if( NULL == oldGamma || NULL == currentGamma ) { if( NULL != oldGamma ) DisposePtr( Ptr( oldGamma ) ); if( NULL != currentGamma ) DisposePtr( Ptr( currentGamma ) ); return rlOutOfMemory; } for( i = 0; i < count; i++ ) { error = GetGamma( screen[i], &oldGamma[i] ); if( noErr != error ) goto exit; } //Loop until we run out of time, resetting the gamma as fast as possible for( double currentTime = GetCurrentTime(); currentTime < endTime; currentTime = GetCurrentTime() ) { //The fraction is the percentage of time that we have spend so far in this loop as a value between 0 and 1.0 double fraction = (currentTime - startTime) / seconds; for( i = 0; i < count; i++ ) { //Calculate the new gamma based on the amount of time spent so far //(1-fraction)startGamma + fraction * endGamma = startGamma + fraction( endGamma - startGamma) for( int j = 0; j < kGammaTableEntryCount; j++ ) { currentGamma[i].red[j] = oldGamma[i].red[j] + fraction * (newGamma[i].red[j] - oldGamma[i].red[j]); currentGamma[i].green[j] = oldGamma[i].green[j] + fraction * (newGamma[i].green[j] - oldGamma[i].green[j]); currentGamma[i].blue[j] = oldGamma[i].blue[j] + fraction * (newGamma[i].blue[j] - oldGamma[i].blue[j]); } error = SetGamma( screen[i], ¤tGamma[i] ); if( noErr != error ) goto finish; } } finish: if( error ) DEBUGMESSAGE( "Got error # " << error << " doing a gamma fade in FadeToGamma(). Attempting to achieve the final gamma...." ); for( i = 0; i < count; i++ ) SetGamma( screen[i], &newGamma[i] ); exit: DisposePtr( Ptr( oldGamma ) ); DisposePtr( Ptr( currentGamma ) ); return error; }
// // AskIfNewResolutionWorks() creates a dialog box in the center of the screen. The dialog asks the // user if the current display setting works. This is necessary because a number of display settings // listed by the OS dont actually work and leave the user with a black screen. The dialog has a 5 // second timeout. If the user does not hit ok within 5 seconds the cancel item is chosen automatically // for him. This feature allows the user to do nothing (which he will probably do if confronted by a // black screen) and still be ok. The method that I have employed to do the timeout requires Appearances // 1.1. I believe this was introduced with OS 8.5. If you want to support back to OS 8.1, then you will // have to do your own modal dialog event proc that implements a timeout. The dialog has not default // button by default. Cmd-period and esc trigger the cancel button. // // OSStatus AskIfNewResolutionWorks( ScreenRef screen ) { DEBUGMESSAGE( "Querying user whether the new resolution works...." ); if( ! screen ) return noErr; //Read the new screen dimensions RLDrawInfo screenData; Rect dialogBounds = {0,0,130, 340}; OSStatus error = GetCurrentScreenDrawingInfo( screen, &screenData ); if( error ) { DEBUGMESSAGE( "Unable to get current screen drawing information. Got back error # " << error ); return error; } //Make a copy of our dialog item list. This will be destroyed when the dialog is destroyed. Handle ditlCopy = LoadDITL(); HandToHand( &ditlCopy ); //Center the dialog rect on the screen { SInt32 horizontalOffset = (SInt32( screenData.bounds.right) + SInt32( screenData.bounds.left ) - SInt32(dialogBounds.right) + SInt32(dialogBounds.left) ) / 2; SInt32 verticalOffset = (SInt32( screenData.bounds.bottom) + SInt32( screenData.bounds.top ) - SInt32(dialogBounds.bottom) + SInt32(dialogBounds.top) ) / 2; dialogBounds.left += horizontalOffset; dialogBounds.right += horizontalOffset; dialogBounds.top += verticalOffset; dialogBounds.bottom += verticalOffset; } //Init a new dialog hidden DialogPtr dialog = NewFeaturesDialog( NULL, &dialogBounds, "\pResolution Verification", true, kWindowModalDialogProc, (WindowPtr) -1L, false, TickCount(), ditlCopy, 0 ); if( ! dialog ) { DEBUGMESSAGE( "Unable to init the \"AskIfNewResolutionWorks\" dialog window. Perhaps there is insufficient free memory or the DITL did not load properly at library startup?" ); return rlOutOfMemory; } //Make sure the dialog cancel item is button # 2 SetDialogCancelItem( dialog, 2 ); //Set dialog to timeout after 5 seconds SetDialogTimeout( dialog, 2, 5 ); for( bool done = false; !done; ) { short itemHit = 0; ModalDialog ( NULL, &itemHit ); switch( itemHit ) { case 2: //cancel DEBUGMESSAGE( "The user hit cancel or the dialog timed out. The new resolution is probably not good." ); done = true; error = rlRezNotFound; break; case 3: //ok DEBUGMESSAGE( "The user hit ok. The new resolution seems to be Okay!" ); done = true; error = noErr; break; } } DisposeDialog( dialog ); return error; }