コード例 #1
0
extern OSStatus MySyncTicketFromPane (
    MyCustomContext context, 
    PMPrintSession session
)

{
    OSStatus result = noErr;
    PMTicketRef ticket = NULL;
    CFMutableDictionaryRef dict = NULL;
    CFDataRef xmlData = NULL;

    result = MyGetTicket (session, kPDE_PMPrintSettingsRef, &ticket);
    if (result == noErr)
    {
        // If our pane has never been shown, this will be a noop.
        SyncSettingsFromPane(context);
        
        dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
                    (const CFDictionaryKeyCallBacks *)&kCFTypeDictionaryKeyCallBacks,
                    (const CFDictionaryValueCallBacks *)&kCFTypeDictionaryValueCallBacks);
        if (dict)
        {
            ExternSettings(&context->settings, dict);
            xmlData = CFPropertyListCreateXMLData(kCFAllocatorDefault, dict);
            if (xmlData)
            {
                result = PMTicketSetCFData (
                    ticket, 
                    kMyBundleIdentifier, 
                    kAppPrintDialogPDEOnlyKey, 
                    xmlData, 
                    kPMUnlocked
                );
                CFRelease(xmlData);
            }
            CFRelease(dict);
        }
    }

    MyDebugMessage("MySyncTicket", result);
    return result;
}
コード例 #2
0
ファイル: PageSetupPDE.c プロジェクト: fruitsamples/App
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	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);
}