extern OSStatus MySyncPaneFromTicket ( MyCustomContext context, PMPrintSession session ) { OSStatus result = noErr; PMTicketRef ticket = NULL; result = MyGetTicket (session, kPDE_PMPrintSettingsRef, &ticket); if (result == noErr) { CFDataRef xmlData = NULL; CFDictionaryRef dict = NULL; result = PMTicketGetCFData ( ticket, kPMTopLevel, kPMTopLevel, kAppPrintDialogPDEOnlyKey, &xmlData ); if (result == noErr) { dict = CFPropertyListCreateFromXMLData ( kCFAllocatorDefault, xmlData, kCFPropertyListImmutable, NULL ); if (dict) { InternSettings(dict, &context->settings); CFRelease(dict); } else result = kPMKeyNotFound; // bad XML? } if (result == kPMKeyNotFound) { InitSettings(&context->settings); result = noErr; } } if (result == noErr) SyncPaneFromSettings(context); MyDebugMessage("MySyncPane", result); return result; }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Name: MyPDESync Input Parameters: context : The plugins context printSession : this holds the tickets syncDirection : A boolean that tells the plugin that it needs to do one of two functions. If true the plugin fetches the values from the tickets and sets the plugins control values. if false the plugin does the opposite, it takes the values out of the plugins' controls and sets them into the tickets Output Parameters: err returns the error status Description: Sets/Gets values in the PageFormat or PrintSettings tickets Change History (most recent first): ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ static OSStatus MyPDESync( PMPDEContext context, PMPrintSession printSession, Boolean syncDirection) { OSStatus err = noErr; PageSetupPDEOnlyContextPtr myContext = NULL; // Pointer to global data block. DebugMessage("PageSetupPDE MyPDESync called\n"); myContext = (PageSetupPDEOnlyContextPtr) context; if ((myContext != NULL) && (printSession != NULL)) { PMTicketRef pageFormatContainer = NULL; err = GetTicketRef(printSession, kPDE_PMPageFormatRef, &pageFormatContainer); if (noErr == err) { CFDataRef ourPDEPageFormatDataRef; Boolean printTitles = false; SInt16 theControlValue = -1; switch (syncDirection) { case kSyncDirectionSetUserInterface: err = PMTicketGetCFData(pageFormatContainer, kPMTopLevel, kPMTopLevel, kAppPageSetupPDEOnlyKey, &ourPDEPageFormatDataRef); if(!err){ if(CFDataGetLength(ourPDEPageFormatDataRef) == sizeof(printTitles)){ printTitles = *(Boolean *)CFDataGetBytePtr(ourPDEPageFormatDataRef); }else printTitles = kPrintTitlesDefault; // default value CFRelease(ourPDEPageFormatDataRef); }else{ // set to default value printTitles = kPrintTitlesDefault; err = noErr; } if (noErr == err) { theControlValue = (printTitles) ? 1 : 0; SetControlValue(myContext->thePrintTitleControlRef, theControlValue); } break; case kSyncDirectionSetTickets: theControlValue = GetControlValue(myContext->thePrintTitleControlRef); printTitles = theControlValue != 0; ourPDEPageFormatDataRef = CFDataCreate(kCFAllocatorDefault, &printTitles, sizeof(printTitles)); if(ourPDEPageFormatDataRef){ err = PMTicketSetCFData(pageFormatContainer, kPMPrintingManager, kAppPageSetupPDEOnlyKey, ourPDEPageFormatDataRef, kPMUnlocked); CFRelease(ourPDEPageFormatDataRef); }else err = memFullErr; break; } } } else err = kPMInvalidPDEContext; DebugPrintErr(err, "PageSetupPDE Error from MyPDESync returned %d\n"); return (err); }