home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / Draw / DrawPageLayout.m < prev    next >
Text File  |  1996-01-08  |  3KB  |  96 lines

  1. #import "draw.h"
  2.  
  3. @implementation DrawPageLayout
  4. /*
  5.  * PageLayout is overridden so that the user can set the margins of
  6.  * the page.  This is important in a Draw program where the user
  7.  * typically wants to maximize the drawable area on the page.
  8.  *
  9.  * The accessory view is used to add the additional fields, and
  10.  * pickedUnits: is overridden so that the margin is displayed in the
  11.  * currently selected units.  Note that the accessoryView is set
  12.  * in InterfaceBuilder using the outlet mechanism!
  13.  *
  14.  * This can be used as an example of how to override Application Kit panels.
  15.  */
  16.  
  17. #ifdef WIN32
  18. - (void)convertOldFactor:(float *)oldf newFactor:(float *)newf
  19. {
  20.     if (oldf) *oldf = 1.0;
  21.     if (newf) *newf = 1.0;
  22. }
  23. #endif
  24.  
  25. - (void)pickedUnits:(id)sender
  26. /*
  27.  * Called when the user selects different units (e.g. cm or inches).
  28.  * Must update the margin fields.
  29.  */
  30. {
  31.     float oldm, newm;
  32.  
  33.     [self convertOldFactor:&oldm newFactor:&newm];
  34.     [leftMargin setFloatValue:newm * [leftMargin floatValue] / oldm];
  35.     [rightMargin setFloatValue:newm * [rightMargin floatValue] / oldm];
  36.     [topMargin setFloatValue:newm * [topMargin floatValue] / oldm];
  37.     [bottomMargin setFloatValue:newm * [bottomMargin floatValue] / oldm];
  38. #ifndef WIN32
  39.     [super pickedUnits:sender];
  40. #endif
  41. }
  42.  
  43. - (void)readPrintInfo
  44. /*
  45.  * Sets the margin fields from the panel's PrintInfo.
  46.  */
  47. {
  48.     NSPrintInfo *pi;
  49.     float conversion, dummy;
  50.  
  51.     [super readPrintInfo];
  52.     pi = [self printInfo];
  53.     [self convertOldFactor:&conversion newFactor:&dummy];
  54.     [leftMargin setFloatValue:[pi leftMargin] * conversion];
  55.     [rightMargin setFloatValue:[pi rightMargin] * conversion];
  56.     [topMargin setFloatValue:[pi topMargin] * conversion];
  57.     [bottomMargin setFloatValue:[pi bottomMargin] * conversion];
  58. }
  59.  
  60. - (void)writePrintInfo
  61. /*
  62.  * Sets the margin values in the panel's PrintInfo from
  63.  * the margin fields in the panel.
  64.  */
  65. {
  66.     NSPrintInfo *pi;
  67.     float conversion, dummy;
  68.  
  69.     [super writePrintInfo];
  70.     pi = [self printInfo];
  71.     [self convertOldFactor:&conversion newFactor:&dummy];
  72.     if (conversion) {
  73.     [pi setLeftMargin:[leftMargin floatValue] / conversion];
  74.     [pi setRightMargin:[rightMargin floatValue] / conversion];
  75.     [pi setTopMargin:[topMargin floatValue] / conversion];
  76.     [pi setBottomMargin:[bottomMargin floatValue] / conversion];
  77.     }
  78. }
  79.  
  80. /* outlet setting methods */
  81.  
  82. - (void)setTopBotForm:anObject
  83. {
  84.     topMargin = [anObject cellWithTag:5];
  85.     bottomMargin = [anObject cellWithTag:6]; 
  86. }
  87.  
  88. - (void)setSideForm:anObject
  89. {
  90.     leftMargin = [anObject cellWithTag:3];
  91.     rightMargin = [anObject cellWithTag:4]; 
  92. }
  93.  
  94. @end
  95.  
  96.