home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / MiniExamples / PaginationLab / MyPageLayout.m < prev    next >
Text File  |  1991-05-18  |  4KB  |  118 lines

  1. /* MyPageLayout.m
  2.  * Purpose: A subclass of the PageLayout panel that displays more of the
  3.  * information from NXApp's PrintInfo object.  If you add an accessory
  4.  * View to the PageLayout panel, you commonly need to subclass it to
  5.  * keep your fields in sync with the user's chosen units.
  6.  *
  7.  * You may freely copy, distribute, and reuse the code in this example.
  8.  * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
  9.  * fitness for any particular use.
  10.  *
  11.  * Written by: Samuel Streeper
  12.  * Created: (04/April/91)
  13.  */
  14.  
  15. #import "MyPageLayout.h"
  16. #import "MyPrintInfo.h"
  17. #import "BigView.h"
  18. #import <appkit/Application.h>
  19. #import <appkit/Form.h>
  20. #import <appkit/ButtonCell.h>
  21. #import <appkit/FormCell.h>
  22.  
  23. @implementation MyPageLayout
  24.  
  25. - (int) runModal
  26. {
  27.     if (!p1AccessoryView)
  28.     {
  29.         //  Initialization probably belongs in new, but [PageLayout new]
  30.         //    does really funky stuff that breaks this...
  31.         //    here we load the nib file that contains our accessory view.
  32.         //  This code only gets executed once, because the nib initializes
  33.         //  the p1AccessoryView outlet to a meaningful value.
  34.         
  35.         [NXApp loadNibSection:"MyPageLayout.nib" owner:self withNames:NO];
  36.         [self setAccessoryView:p1AccessoryView];
  37.     }
  38.  
  39.     return [super runModal];
  40. }
  41.  
  42. - pickedUnits:sender
  43. /*
  44.  * Called when the user selects different units (e.g. cm or inches).
  45.  * Must update the margin fields.
  46.  */
  47. {
  48.     float old, new;
  49.  
  50.     [self convertOldFactor:&old newFactor:&new];
  51.     [[margins cellAt:0:0] setFloatValue:new * [[margins cellAt:0:0] floatValue] / old];
  52.     [[margins cellAt:1:0] setFloatValue:new * [[margins cellAt:1:0] floatValue] / old];
  53.     [[margins cellAt:2:0] setFloatValue:new * [[margins cellAt:2:0] floatValue] / old];
  54.     [[margins cellAt:3:0] setFloatValue:new * [[margins cellAt:3:0] floatValue] / old];
  55.  
  56.     return [super pickedUnits:sender];
  57. }
  58.  
  59. // When the panel comes up, read the global printInfo object and set the
  60. // panels fields appropriately.
  61. - readPrintInfo
  62. {
  63.     float conversion, dummy;
  64.     NXCoord left, right, top, bottom;
  65.     id pi;
  66.     
  67.     [super readPrintInfo];
  68.  
  69.     pi = [NXApp printInfo];
  70.     [[centerButtons cellAt:0:0] setState:[pi isHorizCentered]];
  71.     [[centerButtons cellAt:1:0] setState:[pi isVertCentered]];
  72.  
  73.     [vertButtons selectCellAt:[pi vertPagination]:0];
  74.     [horButtons selectCellAt:[pi horizPagination]:0];
  75.  
  76.     [paginationButtons selectCellAt:([[NXApp printInfo] paginationMode]):0];
  77.     
  78.     [[MyPageLayout new] convertOldFactor:&conversion newFactor:&dummy];
  79.     [pi getMarginLeft:&left right:&right top:&top bottom:&bottom];
  80.     [[margins cellAt:0:0] setFloatValue:left * conversion];
  81.     [[margins cellAt:1:0] setFloatValue:right * conversion];
  82.     [[margins cellAt:2:0] setFloatValue:top * conversion];
  83.     [[margins cellAt:3:0] setFloatValue:bottom * conversion];
  84.  
  85.     return self;
  86. }
  87.  
  88. // If the user hits OK, this method saves the panels settings to the
  89. // global printInfo object.
  90. - writePrintInfo
  91. {
  92.     id pi;
  93.     float conversion, dummy;
  94.  
  95.     [super writePrintInfo];
  96.     pi = [NXApp printInfo];
  97.     [self convertOldFactor:&conversion newFactor:&dummy];
  98.     if (conversion) {
  99.         [pi setMarginLeft:[[margins cellAt:0:0] floatValue] / conversion
  100.                 right:    [[margins cellAt:1:0] floatValue] / conversion
  101.                 top:    [[margins cellAt:2:0] floatValue] / conversion
  102.                 bottom:    [[margins cellAt:3:0] floatValue] / conversion];
  103.     }
  104.     
  105.     [pi setHorizCentered: [[centerButtons cellAt:0:0] state]];
  106.     [pi setVertCentered: [[centerButtons cellAt:1:0] state]];
  107.  
  108.     [pi setVertPagination: [vertButtons selectedRow]];
  109.     [pi setHorizPagination: [horButtons selectedRow]];
  110.  
  111.     [[NXApp printInfo] setPaginationMode:([paginationButtons selectedRow])];
  112.     return self;
  113. }
  114.  
  115.  
  116. @end
  117.  
  118.