home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / mac / programm / 20192 < prev    next >
Encoding:
Text File  |  1992-12-22  |  4.3 KB  |  131 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!uwm.edu!psuvax1!news.ecn.bgu.edu!uxa.ecn.bgu.edu!news.ils.nwu.edu!engber
  3. From: engber@ils.nwu.edu (Mike Engber)
  4. Subject: Re: Software control of landscape/not landscape
  5. Message-ID: <1992Dec22.145106.12576@ils.nwu.edu>
  6. Sender: usenet@ils.nwu.edu (Mr. usenet)
  7. Nntp-Posting-Host: aristotle.ils.nwu.edu
  8. Organization: The Institute for the Learning Sciences
  9. References: <1992Dec18.205137.23378@reed.edu>
  10. Date: Tue, 22 Dec 1992 14:51:06 GMT
  11. Lines: 118
  12.  
  13.  
  14. Attached is the relevant code extracted from SaveATree. It's THINK C code.
  15.  
  16. Basically, there is no official way to get a landscape print record,
  17. but it's somewhat common knowledge that the orientation is controlled
  18. by single bit in the print record (once source for this info is
  19. MacRevealed vol 3). This bit is used for Apple printers and deskwriters
  20. - don't have access to other types of printers to check it out.
  21.  
  22. My conservative approach is to:
  23.  1) flip the bit
  24.  2) use PrValidate to make sure I didn't trash the print record - i.e.
  25.     this driver can't handle this bit being flipped.
  26.  3) use PrGeneral to make sure flipping the bit put the print record
  27.     into landscape mode (instead of doing something else)
  28.  4) if 1-3 didn't work, I prompt the user to pick a landscape record
  29.     from the PrStlDialog I subsequently display. This is sure to work
  30.     unless the user screws up (I display the landscape Icon in the dialog
  31.     in an attempt to make it more foolproof).
  32.  5) Once I get a landscape record I save it away so I'll never have
  33.     to do this again. 
  34.  
  35. This should work pretty well. I don't think it violate any guidlines
  36. (too badly). And I've never had and problems reported wrt to SaveATree
  37. doing it. Some cavats:
  38.  
  39. 1) the printer must have PrGeneral implemented along with the getRotnOp
  40.    opcode (I assume most do nowadays)
  41.  
  42. 2) Older HP deswriter drivers have PrGeneral & getRotnOp implementd, but
  43.    don't return a success error code from PrGeneral. So flipping the bit
  44.    works, but since PrGeneral says it's didn't - I end up prompting the
  45.    user anyway. This bug has been fixed in the more recent drivers.
  46.  
  47. -ME
  48.  
  49. ---
  50.  
  51. void PrintPromptedStyle(THPrint printRecH, Boolean landscape){
  52.     Alert(DU_CenterALRT(landscape ? L_SETUP_ALERT_ID : P_SETUP_ALERT_ID),0L);
  53.     PrOpen();
  54.     PrStlDialog(printRecH);
  55.     PrClose();
  56. }
  57.  
  58. static Boolean PrRotn(THPrint printRecH, Boolean* landscape){
  59.     TGetRotnBlk rotnBlk;
  60.     
  61.     rotnBlk.iOpCode = getRotnOp;
  62.     rotnBlk.hPrint  = printRecH;
  63.     PrGeneral((Ptr)&rotnBlk);
  64.     
  65.     if(rotnBlk.iError == noErr){
  66.         *landscape = rotnBlk.fLandscape ? true : false;
  67.         return true;
  68.     }else{
  69.         return false;
  70.     }
  71. }
  72.  
  73. void PrintDefaultRotn(THPrint printRecH, Boolean landscape){
  74.     Boolean         is_landscape;
  75.     static TPrint   landscapeTPrint;
  76.     static TPrint   portraitTPrint;
  77.     static Boolean  landscapeStored = false;
  78.     static Boolean  portraitStored = false;
  79.     
  80.     PrOpen();
  81.     if(PrintError("\pprint.c: PrintDefaultRotn()","\pPrOpen") != noErr){
  82.         PrClose();
  83.         return;
  84.     }
  85.     
  86.     PrValidate(printRecH);
  87.     
  88.     if(PrRotn(printRecH,&is_landscape)){
  89.         if(is_landscape != landscape){
  90.             /* toggle the bit */
  91.             (*printRecH)->prStl.wDev ^= 0x02;
  92.             /* make sure it worked */
  93.             PrValidate(printRecH);
  94.             if(PrRotn(printRecH,&is_landscape) && is_landscape==landscape){
  95.                 PrClose();
  96.                 return;
  97.             }
  98.         }else{
  99.             /* it was ok to begin with */
  100.             PrClose();
  101.             return;
  102.         }
  103.     }
  104.     
  105.     /*
  106.         If we reach this point either PrGeneral/getRotnOp or the
  107.         bit toggling won't work on this printer. So we'll prompt
  108.         the user & display a style dlog (ugh!).
  109.     */
  110.         PrClose();
  111.         
  112.         if(landscape){
  113.             if(landscapeStored){
  114.                 **printRecH = landscapeTPrint;
  115.             }else{
  116.                 PrintPromptedStyle(printRecH,landscape);
  117.                 landscapeStored = true;
  118.                 landscapeTPrint = **printRecH;
  119.             }
  120.         }else{
  121.             if(portraitStored){
  122.                 **printRecH = portraitTPrint;
  123.             }else{
  124.                 PrintPromptedStyle(printRecH,landscape);
  125.                 portraitStored = true;
  126.                 portraitTPrint = **printRecH;
  127.             }
  128.         }
  129. }
  130.  
  131.