else if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAsIsAndEach) {
else if (howToEnableFrameUI == nsIPrintSettings::kFrameEnableAsIsAndEach) {
static pascal TPPrDlg   MyJobDlgInit(THPrint);        // Our extention to PrJobInitstatic TPPrDlg          gPrtJobDialog;                 // pointer to job dialog static long             prFirstItem;                  // our first item in the extended dialogstatic PItemUPP         prPItemProc;                  // store the old item handler herestatic PRBool           gPrintSelection;static UserItemUPP      gDrawListUPP = nsnull;static nsIPrintSettings	*gPrintSettings=nsnull;typedef struct dialog_item_struct {  Handle  handle;       // handle or procedure pointer for this item */  Rect    bounds;         // display rectangle for this item */  char    type;           // item type - 1 */  char    data[1];        // length byte of data */} DialogItem, *DialogItemPtr, **DialogItemHandle; typedef struct append_item_list_struct {  short max_index;      // number of items - 1   DialogItem  items[1]; // first item in the array} ItemList, *ItemListPtr, **ItemListHandle;#endif/** ------------------------------------------------------- *  Construct the nsDeviceContextSpecMac *  @update   dc 12/02/98 */nsDeviceContextSpecMac::nsDeviceContextSpecMac(): mPrtRec(nsnull), mPrintManagerOpen(PR_FALSE){  NS_INIT_REFCNT();  gPrintSettings = nsnull;}/** ------------------------------------------------------- *  Destroy the nsDeviceContextSpecMac *  @update   dc 12/02/98 */nsDeviceContextSpecMac::~nsDeviceContextSpecMac(){  ClosePrintManager();  if (mPrtRec) {    ::DisposeHandle((Handle)mPrtRec);    mPrtRec = nsnull;  }}NS_IMPL_ISUPPORTS2(nsDeviceContextSpecMac, nsIDeviceContextSpec, nsIPrintingContext)#if !TARGET_CARBON/** ------------------------------------------------------- *  this is a drawing procedure for the user item.. this draws a box around the frameset radio buttons *  @update   dc 12/02/98 */static pascal void MyBBoxDraw(WindowPtr theWindow, short aItemNo){  short   itemType;  Rect    itemBox;  Handle  itemH;  ::GetDialogItem((DialogPtr)gPrtJobDialog, prFirstItem + eDrawFrameID-1, &itemType, &itemH, &itemBox);    // use appearance if possible  if ((long)DrawThemeSecondaryGroup != kUnresolvedCFragSymbolAddress)    ::DrawThemeSecondaryGroup(&itemBox, kThemeStateActive);  else    ::FrameRect(&itemBox);}/** ------------------------------------------------------- *  this is the dialog hook, takes care of setting the dialog items *  @update   dc 12/02/98 */static pascal void MyJobItems(DialogPtr aDialog, short aItemNo){short   myItem, firstItem, i, itemType;short   value;Rect    itemBox;Handle  itemH;  firstItem = prFirstItem;    myItem = aItemNo-firstItem+1;  if (myItem>0) {    switch (myItem) {      case ePrintSelectionCheckboxID:        ::GetDialogItem(aDialog, firstItem, &itemType, &itemH, &itemBox);        gPrintSelection = !gPrintSelection;        ::SetControlValue((ControlHandle)itemH, gPrintSelection);        break;      case ePrintFrameAsIsCheckboxID:      case ePrintSelectedFrameCheckboxID:      case ePrintAllFramesCheckboxID:        for (i=ePrintFrameAsIsCheckboxID; i<=ePrintAllFramesCheckboxID; i++){          ::GetDialogItem(aDialog, firstItem+i-1, &itemType, &itemH, &itemBox);          ::SetControlValue((ControlHandle)itemH, i==myItem);        }        break;              default:        break;    }  } else {    // chain to standard Item handler    CallPItemProc(prPItemProc, aDialog, aItemNo);        if (((TPPrDlg)aDialog)->fDone)    {      //nsCOMPtr<nsIPrintOptions> printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1");      // cleanup and set the print options to what we want      if (gPrintSettings)      {        // print selection        ::GetDialogItem(aDialog, firstItem+ePrintSelectionCheckboxID-1, &itemType, &itemH, &itemBox);        value = ::GetControlValue((ControlHandle)itemH);        if (1==value){          gPrintSettings->SetPrintRange(nsIPrintOptions::kRangeSelection);        } else {          gPrintSettings->SetPrintRange(nsIPrintOptions::kRangeAllPages);        }                // print frames as is        ::GetDialogItem(aDialog, firstItem+ePrintFrameAsIsCheckboxID-1, &itemType, &itemH, &itemBox);        value = ::GetControlValue((ControlHandle)itemH);        if (1==value){          gPrintSettings->SetPrintFrameType(nsIPrintOptions::kFramesAsIs);        }                // selected frame        ::GetDialogItem(aDialog, firstItem+ePrintSelectedFrameCheckboxID-1, &itemType, &itemH, &itemBox);        value = ::GetControlValue((ControlHandle)itemH);        if (1==value){          gPrintSettings->SetPrintFrameType(nsIPrintOptions::kSelectedFrame);        }                // print all frames        ::GetDialogItem(aDialog, firstItem+ePrintAllFramesCheckboxID-1, &itemType, &itemH, &itemBox);        value = ::GetControlValue((ControlHandle)itemH);        if (1==value){          gPrintSettings->SetPrintFrameType(nsIPrintOptions::kEachFrameSep);        }              }    }  }}/** ------------------------------------------------------- *  Append DITL items to the dialog *  @update   dc 05/04/2001 */static PRInt32  AppendToDialog(TPPrDlg  aDialog, PRInt32  aDITLID){nsresult        theResult = NS_ERROR_FAILURE;short           firstItem;ItemListHandle  myAppendDITLH;ItemListHandle  dlg_Item_List;  dlg_Item_List = (ItemListHandle)((DialogPeek)aDialog)->items;  firstItem = (**dlg_Item_List).max_index+2;  theResult = nsMacResources::OpenLocalResourceFile();  if (theResult == NS_OK) {    myAppendDITLH = (ItemListHandle)::GetResource('DITL', aDITLID);    if (nsnull == myAppendDITLH) {      // some sort of error      theResult = NS_ERROR_FAILURE;    } else {      ::AppendDITL((DialogPtr)aDialog, (Handle)myAppendDITLH, appendDITLBottom);      ::ReleaseResource((Handle) myAppendDITLH);    }  theResult = nsMacResources::CloseLocalResourceFile();  }  return firstItem;}/** ------------------------------------------------------- *  Initialize the print dialogs additional items *  @update   dc 05/04/2001 */static pascal TPPrDlg MyJobDlgInit(THPrint aHPrint){  PRInt32 i;  short   itemType;  Handle  itemH;  Rect    itemBox;  PRBool  isOn;  PRInt16 howToEnableFrameUI = nsIPrintOptions::kFrameEnableNone;  prFirstItem = AppendToDialog(gPrtJobDialog, DITL_ADDITIONS);  //nsCOMPtr<nsIPrintOptions> printOptionsService = do_GetService("@mozilla.org/gfx/printoptions;1");  if (gPrintSettings) {    gPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn);    gPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI);  }  ::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+ePrintSelectionCheckboxID-1, &itemType, &itemH, &itemBox);  if ( isOn ) {    ::HiliteControl((ControlHandle)itemH, 0);  } else {    ::HiliteControl((ControlHandle)itemH, 255);   }    gPrintSelection = PR_FALSE;  ::SetControlValue((ControlHandle) itemH, gPrintSelection);  if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAll) {    for (i = ePrintFrameAsIsCheckboxID; i <= ePrintAllFramesCheckboxID; i++){      ::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+i-1, &itemType, &itemH, &itemBox);      ::SetControlValue((ControlHandle) itemH, (i==4));      ::HiliteControl((ControlHandle)itemH, 0);    }  }  else if (howToEnableFrameUI == nsIPrintOptions::kFrameEnableAsIsAndEach) {    for (i = ePrintFrameAsIsCheckboxID; i <= ePrintAllFramesCheckboxID; i++){      ::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+i-1, &itemType, &itemH, &itemBox);      ::SetControlValue((ControlHandle) itemH, (i==4));      if ( i == 3){        ::HiliteControl((ControlHandle)itemH, 255);      }    }  }  else {    for (i = ePrintFrameAsIsCheckboxID; i <= ePrintAllFramesCheckboxID; i++){      ::GetDialogItem((DialogPtr) gPrtJobDialog, prFirstItem+i-1, &itemType, &itemH, &itemBox);      ::SetControlValue((ControlHandle) itemH, FALSE);      ::HiliteControl((ControlHandle)itemH, 255);     }  }    // attach our handler  prPItemProc = gPrtJobDialog->pItemProc;  gPrtJobDialog->pItemProc = NewPItemUPP(MyJobItems);  // attach a draw routine  gDrawListUPP = NewUserItemProc(MyBBoxDraw);  ::GetDialogItem((DialogPtr)gPrtJobDialog, prFirstItem+eDrawFrameID-1, &itemType, &itemH, &itemBox);  ::SetDialogItem((DialogPtr)gPrtJobDialog, prFirstItem+eDrawFrameID-1, itemType, (Handle)gDrawListUPP, &itemBox);  return gPrtJobDialog;}