Back to index

lightning-sunbird  0.9+nobinonly
Classes | Enumerations | Functions
PDECore.c File Reference
#include <Carbon/Carbon.h>
#include <Print/PMPrintingDialogExtensions.h>
#include "PDECustom.h"
#include "PDEUtilities.h"

Go to the source code of this file.

Classes

struct  MyIUnknownInstance
struct  MyPDEInstance

Enumerations

enum  SyncDirection { kSyncTicketFromPane = FALSE, kSyncPaneFromTicket = TRUE }

Functions

static HRESULT MyQueryInterface (void *, REFIID, LPVOID *)
static ULONG MyIUnknownRetain (void *)
static ULONG MyIUnknownRelease (void *)
static OSStatus MyPMRetain (PMPlugInHeaderInterface *)
static OSStatus MyPMRelease (PMPlugInHeaderInterface **)
static OSStatus MyPMGetAPIVersion (PMPlugInHeaderInterface *, PMPlugInAPIVersion *)
static OSStatus MyPrologue (PMPDEContext *, OSType *, CFStringRef *, CFStringRef *, UInt32 *, UInt32 *)
static OSStatus MyInitialize (PMPDEContext, PMPDEFlags *, PMPDERef, ControlRef, PMPrintSession)
static OSStatus MySync (PMPDEContext, PMPrintSession, Boolean)
static OSStatus MyGetSummary (PMPDEContext, CFArrayRef *, CFArrayRef *)
static OSStatus MyOpen (PMPDEContext)
static OSStatus MyClose (PMPDEContext)
static OSStatus MyTerminate (PMPDEContext, OSStatus)
voidMyCFPlugInFactory (CFAllocatorRef allocator, CFUUIDRef typeUUID)

Class Documentation

struct MyIUnknownInstance

Definition at line 97 of file PDECore.c.

Class Members
CFUUIDRef factoryID
SInt32 refCount
const IUnknownVTbl * vtable
struct MyPDEInstance

Definition at line 105 of file PDECore.c.

Class Members
SInt32 refCount
const PlugInIntfVTable * vtable

Enumeration Type Documentation

Enumerator:
kSyncTicketFromPane 
kSyncPaneFromTicket 

Definition at line 60 of file PDECore.c.


Function Documentation

void* MyCFPlugInFactory ( CFAllocatorRef  allocator,
CFUUIDRef  typeUUID 
)

Definition at line 128 of file PDECore.c.

{
    // our IUnknown interface function table
    static const IUnknownVTbl sMyIUnknownVTable =
    {
        NULL, // required padding for COM
        MyQueryInterface,
        MyIUnknownRetain,
        MyIUnknownRelease
    };
    
    CFBundleRef         myBundle    = NULL;
    CFDictionaryRef     myTypes     = NULL;
    CFStringRef         requestType = NULL;
    CFArrayRef          factories   = NULL;
    CFStringRef         factory     = NULL;
    CFUUIDRef           factoryID   = NULL;
    MyIUnknownInstance  *instance   = NULL;

    myBundle = MyGetBundle();

    if (myBundle != NULL)
    {
        myTypes = CFBundleGetValueForInfoDictionaryKey (
            myBundle, CFSTR("CFPlugInTypes"));
    
        if (myTypes != NULL) 
        {
            // get a reference to the requested type 
            // verify that the requested type matches my type (it should!)
            requestType = CFUUIDCreateString (allocator, typeUUID);
            if (requestType != NULL)
            {
                factories = CFDictionaryGetValue (myTypes, requestType);
                CFRelease (requestType);
                if (factories != NULL) 
                {   // assume the factory we want is entry [0]
                    factory = CFArrayGetValueAtIndex (factories, 0);
                    if (factory != NULL) 
                    {
                       // get a reference to my factory ID
                        factoryID = CFUUIDCreateFromString (
                            allocator, factory);
                        if (factoryID != NULL)
                        {
                            // construct an instance of the IUnknown interface
                            instance = malloc (sizeof(MyIUnknownInstance));
                            if (instance != NULL)
                            {
                                instance->vtable = &sMyIUnknownVTable;
                                instance->refCount = 1;
                                instance->factoryID = factoryID;
                                CFPlugInAddInstanceForFactory (factoryID);
                            }
                            else {
                                CFRelease (factoryID);
                            }
                        }
                    }
                }
            }
        }
    }

    MyDebugMessage ("Factory", (SInt32) instance);
    return instance;
}

Here is the call graph for this function:

static OSStatus MyClose ( PMPDEContext  inContext) [static]

Definition at line 695 of file PDECore.c.

{
    MyContext context = (MyContext) inContext;
    OSStatus result = noErr;

    result = MyRemoveHelpEventHandler (
        &(context->helpHandler),
        &(context->helpHandlerUPP)
    );

    MyDebugMessage("MyClose", result);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static OSStatus MyGetSummary ( PMPDEContext  inContext,
CFArrayRef *  titles,
CFArrayRef *  values 
) [static]

Definition at line 565 of file PDECore.c.

{
    MyContext context = (MyContext) inContext;
    CFMutableArrayRef titleArray = NULL;
    CFMutableArrayRef valueArray = NULL;

    // assume the worst
    OSStatus result = kPMInvalidPDEContext;

    // when the second argument to CFArrayCreateMutable is 0, 
    // the array size is not fixed

    titleArray = CFArrayCreateMutable (
        kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);

    if (titleArray != NULL)
    {
        valueArray = CFArrayCreateMutable (
            kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks);

        if (valueArray != NULL)
        {
            result = MyGetSummaryText (
                context->customContext, 
                titleArray, 
                valueArray
            );
        }
    }

    if (result != noErr)
    {
        if (titleArray != NULL)
        {
            CFRelease (titleArray);
            titleArray = NULL;
        }
        if (valueArray != NULL)
        {
            CFRelease (valueArray);
            valueArray = NULL;
        }
    }

    *titles = titleArray;
    *values = valueArray;

    MyDebugMessage("MyGetSummary", result);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static OSStatus MyInitialize ( PMPDEContext  inContext,
PMPDEFlags *  flags,
PMPDERef  ref,
ControlRef  userPane,
PMPrintSession  session 
) [static]

Definition at line 503 of file PDECore.c.

{
    MyContext context = (MyContext) inContext;
    OSStatus result = noErr;

    *flags = kPMPDENoFlags;
    context->userPane = userPane;

    result = MySync (
        inContext, session, kSyncPaneFromTicket);

    MyDebugMessage("MyInitialize", result);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static ULONG MyIUnknownRelease ( void this) [static]

Definition at line 337 of file PDECore.c.

{
    MyIUnknownInstance* instance = (MyIUnknownInstance*) this;
    ULONG refCount = 0;

    if (instance != NULL)
    {
        refCount = --instance->refCount;
        if (refCount == 0)
        {
            CFPlugInRemoveInstanceForFactory (instance->factoryID);
            CFRelease (instance->factoryID);
            free (instance);
        }
    }

    MyDebugMessage("MyIUnknownRelease", refCount);
    return refCount;      
}

Here is the call graph for this function:

Here is the caller graph for this function:

static ULONG MyIUnknownRetain ( void this) [static]

Definition at line 309 of file PDECore.c.

{   
    MyIUnknownInstance* instance = (MyIUnknownInstance*) this;
    ULONG refCount = 1;
        
    if (instance != NULL) {
        refCount = ++instance->refCount;
    }

    MyDebugMessage("MyIUnknownRetain", refCount);
    return refCount;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static OSStatus MyOpen ( PMPDEContext  inContext) [static]

Definition at line 628 of file PDECore.c.

{
    MyContext context = (MyContext) inContext;
    OSStatus result = noErr;

    if (!context->initialized)
    {
        // initialize pane
    
        IBNibRef nib = NULL;
    
        result = CreateNibReferenceWithCFBundle (
            MyGetBundle(), 
            kMyNibFile,
            &nib
        );

        if (result == noErr)
        {
            WindowRef nibWindow = NULL;
 
            result = CreateWindowFromNib (
                nib, 
                kMyNibWindow, 
                &nibWindow
            );

            if (result == noErr)
            {
                result = MyEmbedCustomControls (
                    context->customContext, 
                    nibWindow, 
                    context->userPane
                );

                if (result == noErr)
                {
                    context->initialized = TRUE;
                }

                DisposeWindow (nibWindow);
            }

            DisposeNibReference (nib);
        }
    }

    if (context->initialized)
    {
        result = MyInstallHelpEventHandler (
            GetControlOwner (context->userPane), 
            &(context->helpHandler),
            &(context->helpHandlerUPP)
        );
    }
    
    MyDebugMessage("MyOpen", result);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static OSStatus MyPMGetAPIVersion ( PMPlugInHeaderInterface *  this,
PMPlugInAPIVersion *  versionPtr 
) [static]

Definition at line 421 of file PDECore.c.

{
    OSStatus result = noErr;

    // constants defined in PMPrintingDialogExtensions.h
    versionPtr->buildVersionMajor = kPDEBuildVersionMajor;
    versionPtr->buildVersionMinor = kPDEBuildVersionMinor;
    versionPtr->baseVersionMajor = kPDEBaseVersionMajor;
    versionPtr->baseVersionMinor = kPDEBaseVersionMinor;
    
    MyDebugMessage("MyPMGetAPIVersion", result);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static OSStatus MyPMRelease ( PMPlugInHeaderInterface **  this) [static]

Definition at line 385 of file PDECore.c.

{
    MyPDEInstance* instance = (MyPDEInstance*) *this;
    ULONG refCount = 0;
    OSStatus result = noErr;

    // clear caller's instance variable (don't ask)
    *this = NULL;

    if(instance != NULL)
    {
        // decrement instance reference count, and free if zero
        refCount = --instance->refCount;
    
        if (refCount == 0) 
        {
            free (instance);
            MyFreeTitle();
            MyFreeBundle();
        }
    }

    MyDebugMessage("MyPMRelease", refCount);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static OSStatus MyPMRetain ( PMPlugInHeaderInterface *  this) [static]

Definition at line 364 of file PDECore.c.

{
    MyPDEInstance* instance = (MyPDEInstance*) this;
    ULONG refCount = 1;
    OSStatus result = noErr;
    
    if (instance != NULL) {
        refCount = ++instance->refCount;
    }

    MyDebugMessage("MyPMRetain", refCount);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static OSStatus MyPrologue ( PMPDEContext *  outContext,
OSType creator,
CFStringRef *  paneKind,
CFStringRef *  title,
UInt32 maxH,
UInt32 maxV 
) [static]

Definition at line 458 of file PDECore.c.

{
    MyContext context = NULL;
    OSStatus result = kPMInvalidPDEContext;

    context = malloc (sizeof (MyContextBlock));

    if (context != NULL)
    {
        context->customContext = MyCreateCustomContext();
        context->initialized = FALSE;
        context->userPane = NULL;
        context->helpHandler = NULL;
        context->helpHandlerUPP = NULL;

        // assign output parameters
        *outContext = (PMPDEContext) context;
        *creator    = kMozPDECreatorCode;
        *paneKind   = kMyPaneKindID;
        *title      = MyGetTitle();
        *maxH       = kMyMaxH;
        *maxV       = kMyMaxV;

        result = noErr;
    }

    MyDebugMessage("MyPrologue", result);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static HRESULT MyQueryInterface ( void this,
REFIID  iID,
LPVOID ppv 
) [static]

Definition at line 214 of file PDECore.c.

{

    // PDE interface function table

    static const PlugInIntfVTable sMyPDEVTable = 
    { 
        {
            MyPMRetain,
            MyPMRelease, 
            MyPMGetAPIVersion 
        },
        MyPrologue,
        MyInitialize,
        MySync,
        MyGetSummary,
        MyOpen,
        MyClose,
        MyTerminate
    };


    CFUUIDRef requestID = NULL;
    CFUUIDRef actualID  = NULL;
    HRESULT   result = E_UNEXPECTED;

    
    // get a reference to the UUID for the requested interface
    requestID = CFUUIDCreateFromUUIDBytes (kCFAllocatorDefault, iID);
    if (requestID != NULL)
    {
        // get a reference to the UUID for all PDE interfaces
        actualID = CFUUIDCreateFromString (kCFAllocatorDefault, kDialogExtensionIntfIDStr);
        if (actualID != NULL)
        {
            if (CFEqual (requestID, actualID))
            {
                // caller wants an instance of my PDE interface
        
                MyPDEInstance *instance = malloc (sizeof(MyPDEInstance));
        
                if (instance != NULL)
                {
                    instance->vtable = &sMyPDEVTable;
                    instance->refCount = 1;
                    *ppv = instance;
                    result = S_OK;
                }
            }
            else
            {
                if (CFEqual (requestID, IUnknownUUID))
                {
                    // caller wants an instance of my IUnknown interface
                    MyIUnknownRetain (this);
                    *ppv = this;
                    result = S_OK;
                }
                else
                {
                    *ppv = NULL;
                    result = E_NOINTERFACE;
                }
            }
            CFRelease (actualID);
        }
        CFRelease (requestID);
    }

    MyDebugMessage("MyQueryInterface", result);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static OSStatus MySync ( PMPDEContext  inContext,
PMPrintSession  session,
Boolean  syncDirection 
) [static]

Definition at line 532 of file PDECore.c.

{
    MyContext context = (MyContext) inContext;
    OSStatus result = noErr;

    if (syncDirection == kSyncPaneFromTicket)
    {
        result = MySyncPaneFromTicket (context->customContext, session);
    }
    else
    {
        result = MySyncTicketFromPane (context->customContext, session);
    }

    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static OSStatus MyTerminate ( PMPDEContext  inContext,
OSStatus  inStatus 
) [static]

Definition at line 716 of file PDECore.c.

{
    MyContext context = (MyContext) inContext;
    OSStatus result = noErr;

    if (context != NULL)
    {
        result = MyRemoveHelpEventHandler (
            &(context->helpHandler),
            &(context->helpHandlerUPP)
        );

        if (context->customContext != NULL) {
            MyReleaseCustomContext (context->customContext);
        }

        free (context);
    }

    MyDebugMessage("MyTerminate", result);
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function: