home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / YellowBox / Kits / MiscTableScroll-138.1 / Examples / LazyScrollDir / SD_PageLayout.m < prev    next >
Encoding:
Text File  |  1998-03-31  |  6.8 KB  |  209 lines

  1. //=============================================================================
  2. //
  3. //    Copyright (C) 1996-1997 by Paul S. McCarthy and Eric Sunshine.
  4. //        Written by Paul S. McCarthy and Eric Sunshine.
  5. //                All Rights Reserved.
  6. //
  7. //    This notice may not be removed from this source code.
  8. //
  9. //    This object is included in the MiscKit by permission from the authors
  10. //    and its use is governed by the MiscKit license, found in the file
  11. //    "License.rtf" in the MiscKit distribution.  Please refer to that file
  12. //    for a list of all applicable permissions and restrictions.
  13. //
  14. //=============================================================================
  15. //-----------------------------------------------------------------------------
  16. // SD_PageLayout.m
  17. //
  18. //    Custom subclass of NeXT's appkit PageLayout panel that adds
  19. //    user controls for:
  20. //
  21. //        Margins
  22. //        Pagination
  23. //        Centering
  24. //
  25. //-----------------------------------------------------------------------------
  26. //-----------------------------------------------------------------------------
  27. // $Id: SD_PageLayout.m,v 1.2 97/04/25 20:01:30 sunshine Exp $
  28. // $Log:    SD_PageLayout.m,v $
  29. // Revision 1.2  97/04/25  20:01:30  sunshine
  30. // v14.2: Ported to OPENSTEP 4.2 prerelease for Windows NT by working around
  31. // incompatiblities between Mach and NT NSPageLayout implementations.
  32. // 
  33. // Revision 1.1  97/03/23  02:07:06  sunshine
  34. // v14.1: Page layout panel.
  35. //-----------------------------------------------------------------------------
  36. #import    "SD_PageLayout.h"
  37.  
  38. #import    <AppKit/NSApplication.h>
  39. #import    <AppKit/NSButton.h>
  40. #import    <AppKit/NSMatrix.h>
  41. #import    <AppKit/NSPrintInfo.h>
  42. #import    <AppKit/NSTextField.h>
  43. #import    <Foundation/NSBundle.h>
  44.  
  45.  
  46. @implementation SD_PageLayout
  47. //-----------------------------------------------------------------------------
  48. // loadAccessoryView
  49. //-----------------------------------------------------------------------------
  50. - (void)loadAccessoryView
  51.     {
  52.     NSView* v;
  53.     [NSBundle loadNibNamed:@"SD_PageLayout" owner:self];
  54.     v = [[[accessoryWindow contentView] retain] autorelease];
  55.  
  56.     [accessoryWindow setContentView:0];
  57.     [accessoryWindow close];
  58.     [accessoryWindow release];
  59.     [self setAccessoryView:v];
  60.     }
  61.  
  62.  
  63. //-----------------------------------------------------------------------------
  64. // pageLayout
  65. //-----------------------------------------------------------------------------
  66. + (NSPageLayout*)pageLayout
  67.     {
  68.     static id p = 0;
  69.     if (p == 0)
  70.     {
  71.     p = [[super pageLayout] retain];
  72.     [p loadAccessoryView];
  73.     }
  74.     return p;
  75.     }
  76.  
  77.  
  78. //-----------------------------------------------------------------------------
  79. // launch:
  80. //-----------------------------------------------------------------------------
  81. + (void)launch:(id)sender
  82.     {
  83.     [SD_PageLayout pageLayout];
  84.     [NSApp runPageLayout:sender];
  85.     }
  86.  
  87.  
  88. //-----------------------------------------------------------------------------
  89. // convertOldFactor:newFactor:
  90. //    Missing from OPENSTEP for Windows, so dummy one up.
  91. //-----------------------------------------------------------------------------
  92. #ifdef __WIN32__
  93. - (void)convertOldFactor:(float*)old_factor newFactor:(float*)new_factor
  94.     {
  95.     if (old_factor != 0) *old_factor = 1.0;
  96.     if (new_factor != 0) *new_factor = 1.0;
  97.     }
  98. #endif
  99.  
  100.  
  101. //-----------------------------------------------------------------------------
  102. // pickedUnits:
  103. //-----------------------------------------------------------------------------
  104. - (void)pickedUnits:(id)sender
  105.     {
  106.     float old_factor, new_factor, scaler;
  107.  
  108.     [self convertOldFactor:&old_factor newFactor:&new_factor];
  109.     scaler = new_factor / old_factor;
  110.  
  111.     [leftMarginField   setFloatValue:[leftMarginField   floatValue] * scaler];
  112.     [rightMarginField  setFloatValue:[rightMarginField  floatValue] * scaler];
  113.     [topMarginField    setFloatValue:[topMarginField    floatValue] * scaler];
  114.     [bottomMarginField setFloatValue:[bottomMarginField floatValue] * scaler];
  115.  
  116. #ifndef __WIN32__    // Missing from OPENSTEP for Windows.
  117.     [super pickedUnits:sender];
  118. #endif
  119.     }
  120.  
  121.  
  122. //-----------------------------------------------------------------------------
  123. // pagination_to_slot
  124. //-----------------------------------------------------------------------------
  125. static int pagination_to_slot( int pg )
  126.     {
  127.     int slot = 1;
  128.     if (pg == NSFitPagination)
  129.     slot = 0;
  130.     else if (pg == NSClipPagination)
  131.     slot = 2;
  132.     return slot;
  133.     }
  134.  
  135.  
  136. //-----------------------------------------------------------------------------
  137. // slot_to_pagination
  138. //-----------------------------------------------------------------------------
  139. static int slot_to_pagination( int slot )
  140.     {
  141.     int pg = NSAutoPagination;
  142.     if (slot == 0)
  143.     pg = NSFitPagination;
  144.     else if (slot == 2)
  145.     pg = NSClipPagination;
  146.     return pg;
  147.     }
  148.  
  149.  
  150. //-----------------------------------------------------------------------------
  151. // readPrintInfo
  152. //-----------------------------------------------------------------------------
  153. - (void)readPrintInfo
  154.     {
  155.     NSPrintInfo* pinfo;
  156.     int pg_row, pg_col;
  157.     float left,right,top,bottom;
  158.     float old_factor, new_factor;
  159.     [super readPrintInfo];
  160.     pinfo = [self printInfo];
  161.  
  162.     left   = [pinfo leftMargin  ];
  163.     right  = [pinfo rightMargin ];
  164.     top    = [pinfo topMargin   ];
  165.     bottom = [pinfo bottomMargin];
  166.     [self convertOldFactor:&old_factor newFactor:&new_factor];
  167.  
  168.     [leftMarginField    setFloatValue:new_factor * left  ];
  169.     [rightMarginField    setFloatValue:new_factor * right ];
  170.     [topMarginField    setFloatValue:new_factor * top   ];
  171.     [bottomMarginField    setFloatValue:new_factor * bottom];
  172.  
  173.     [centerMatrix selectCellAtRow:(int)[pinfo isVerticallyCentered]
  174.                column:(int)[pinfo isHorizontallyCentered]];
  175.  
  176.     pg_row = pagination_to_slot( [pinfo verticalPagination] );
  177.     pg_col = pagination_to_slot( [pinfo horizontalPagination] );
  178.     [paginationMatrix selectCellAtRow:pg_row column:pg_col];
  179.     }
  180.  
  181.  
  182. //-----------------------------------------------------------------------------
  183. // writePrintInfo
  184. //-----------------------------------------------------------------------------
  185. - (void)writePrintInfo
  186.     {
  187.     NSPrintInfo* pinfo;
  188.     float old_factor, new_factor;
  189.     [super writePrintInfo];
  190.     pinfo = [self printInfo];
  191.  
  192.     [self convertOldFactor:&old_factor newFactor:&new_factor];
  193.  
  194.     [pinfo setLeftMargin:  [leftMarginField   floatValue] / old_factor];
  195.     [pinfo setRightMargin: [rightMarginField  floatValue] / old_factor];
  196.     [pinfo setTopMargin:   [topMarginField    floatValue] / old_factor];
  197.     [pinfo setBottomMargin:[bottomMarginField floatValue] / old_factor];
  198.  
  199.     [pinfo setVerticallyCentered:  [centerMatrix selectedRow   ]];
  200.     [pinfo setHorizontallyCentered:[centerMatrix selectedColumn]];
  201.  
  202.     [pinfo setHorizontalPagination:
  203.         slot_to_pagination([paginationMatrix selectedColumn])];
  204.     [pinfo setVerticalPagination:
  205.         slot_to_pagination([paginationMatrix selectedRow])];
  206.     }
  207.  
  208. @end
  209.