home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / ImageWriter--custom dialogs / CommonCode.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-20  |  3.9 KB  |  151 lines  |  [TEXT/MPS ]

  1. /*
  2.     copyright © 1992-1994 Apple Computer Inc.  All rights reserved.
  3.     
  4.     CommonCode.c
  5.     This file contains routines that are used by both the old and the new
  6.     API files.  We have to include them with both links, and it's best
  7.     to have just use one copy stored here.
  8.     
  9.     Modification history
  10.     11/16/93            dmh -    begat.
  11. */
  12.  
  13. #include <GXExceptions.h>
  14. #include <Packages.h>
  15. #include <Dialogs.h>
  16. #include <Errors.h>
  17. #include <Resources.h>
  18. #include <GXPrinterDrivers.h>        // Standard printing includes
  19. #include "CommonDefines.h"            // things common to .r and .h files
  20.  
  21.  
  22. // StoreFmtCollectionItem stores the passed data as specified,
  23. // in the collection of the passed format.
  24.  
  25. OSErr StoreFmtCollectionItem(void *collectItem, long collectSize,
  26.                              OSType collectType, short collectID,
  27.                              gxFormat whichFormat)
  28. {
  29.     OSErr        err;
  30.     Collection    fmtCollection;
  31.     long        index, itemSize, attributes;
  32.  
  33. // Get the format collection of the passed format, and see if
  34. // this item already exists.
  35.  
  36.     fmtCollection = GXGetFormatCollection(whichFormat);
  37.  
  38.     err = GetCollectionItemInfo(fmtCollection,
  39.                                 collectType,
  40.                                 collectID,
  41.                                 &index,
  42.                                 &itemSize,
  43.                                 &attributes);
  44.  
  45.  
  46. // If the collection item already exists, replace the old data with
  47. // what we were passed.  If the item doesn't exist, create it.
  48.  
  49.     if (!err)
  50.     {
  51.         err = ReplaceIndexedCollectionItem(fmtCollection,
  52.                                            index,
  53.                                            collectSize,
  54.                                            collectItem);
  55.     }
  56.     else
  57.         if (err == collectionItemNotFoundErr)
  58.             err = AddCollectionItem(fmtCollection,
  59.                                     collectType,
  60.                                     collectID,
  61.                                     collectSize,
  62.                                     collectItem);
  63.     return err;
  64. }
  65.  
  66.  
  67.  
  68. // GetFmtCollectionItem returns the requested format collection item.
  69.  
  70. OSErr GetFmtCollectionItem(void *collectItem, long *collectSize,
  71.                            OSType collectType, short collectID,
  72.                            gxFormat whichFormat)
  73. {
  74.     OSErr        err;
  75.     Collection    fmtCollection;
  76.  
  77.     fmtCollection = GXGetFormatCollection(whichFormat);
  78.  
  79.     err = GetCollectionItem(fmtCollection,
  80.                             collectType,
  81.                             collectID,
  82.                             collectSize,
  83.                             collectItem);
  84.     return err;
  85. }
  86.  
  87.  
  88.  
  89. // SetFormatFlipping simply stores the 'flph' and 'flpv' format
  90. // collection tags, representing the setting passed.  That is,
  91. //
  92. //    flipSetting == 0 -- no flipping.
  93. //    flipSetting == 1 -- horizontal flipping.
  94. //    flipSetting == 2 -- vertical flipping.
  95. //    flipSetting == 3 -- horizontal & vertical flipping.
  96. //
  97. // Note that the 'flph' and 'flpv' tags are only supported by the
  98. // GX PostScript imaging engine, so we need to provide support for
  99. // handling these tags ourselves.  We do this in the SD_RenderPage
  100. // routine in NewApp.c
  101.  
  102. void SetFormatFlipping(char flipSetting, gxFormat whichFormat)
  103. {
  104.     gxFlipPageHorizontalInfo    hFlipInfo;
  105.     gxFlipPageVerticalInfo        vFlipInfo;
  106.  
  107. // Simply store the collection items indicating the requested page
  108. // flipping.
  109.  
  110.     hFlipInfo.flipHorizontal = (flipSetting & 0x01) != 0;
  111.     vFlipInfo.flipVertical   = (flipSetting & 0x02) != 0;
  112.     
  113.     StoreFmtCollectionItem(&hFlipInfo, sizeof(gxFlipPageHorizontalInfo),
  114.                            gxFlipPageHorizontalTag, gxPrintingTagID,
  115.                            whichFormat);
  116.  
  117.     StoreFmtCollectionItem(&vFlipInfo, sizeof(gxFlipPageVerticalInfo),
  118.                            gxFlipPageVerticalTag, gxPrintingTagID,
  119.                            whichFormat);
  120. }
  121.  
  122.  
  123.  
  124. // GetCurFlip returns a character value which indicates the current
  125. // flipping settings in the options dialog.  The char's value can be
  126. // interpreted like so:
  127. //
  128. //    0 -- no flipping.
  129. //    1 -- horizontal flipping.
  130. //    2 -- vertical flipping.
  131. //    3 -- horizontal & vertical flipping.
  132. //
  133. // hFlipBox and vFlipBox are the DITL item numbers of the horizontal
  134. // and vertical checkboxes in this panel or dialog.
  135.  
  136.  
  137. char GetCurFlip(DialogPtr theDialog, short hFlipBox, short vFlipBox)
  138. {
  139.     char        curFlipping;
  140.     short        itemType;
  141.     Handle        itemH;
  142.     Rect        itemBox;
  143.  
  144.     GetDItem(theDialog, hFlipBox, &itemType, &itemH, &itemBox);
  145.     curFlipping = GetCtlValue((ControlHandle) itemH);
  146.     GetDItem(theDialog, vFlipBox, &itemType, &itemH, &itemBox);
  147.     curFlipping += GetCtlValue((ControlHandle) itemH) *2;
  148.     
  149.     return curFlipping;
  150. }
  151.