home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / DEV.Z / FixedSizeAspect.m < prev    next >
Encoding:
Text File  |  1996-04-17  |  2.2 KB  |  72 lines

  1. /*
  2.         FixedSizeAspect.m
  3.         TextSizingExample
  4.  
  5.         Author: Mike Ferris
  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,
  9.     as to its fitness for any particular use.
  10. */
  11.  
  12. #import "FixedSizeAspect.h"
  13. #import "Controller.h"
  14.  
  15. @implementation FixedSizeAspect
  16.  
  17. - (void)dealloc {
  18.     [[[self controller] textStorage] removeLayoutManager:_layoutManager];
  19.     [_layoutManager release];
  20.     [super dealloc];
  21. }
  22.  
  23. - (NSString *)aspectName {
  24.     return NSLocalizedString(@"Non-scrolling Text", @"Display name for FixedSizeAspect.");
  25. }
  26.  
  27. - (void)didLoadNib {
  28.     NSTextStorage *textStorage = [[self controller] textStorage];
  29.     NSView *aspectView = [self aspectView];
  30.     NSRect frame;
  31.     NSTextContainer *textContainer;
  32.     NSTextView *textView;
  33.  
  34.     [super didLoadNib];
  35.  
  36.     // Figure frame for NSTextView (and NSTextContainer size)
  37.     frame = NSInsetRect([aspectView bounds], 8.0, 8.0);
  38.     
  39.     // Create NSSLayoutManager
  40.     _layoutManager = [[NSLayoutManager allocWithZone:[self zone]] init];
  41.     [textStorage addLayoutManager:_layoutManager];
  42.  
  43.     // Create and configure NSTextContainer
  44.     textContainer = [[NSTextContainer allocWithZone:[self zone]] initWithContainerSize:frame.size];
  45.     [textContainer setWidthTracksTextView:YES];
  46.     [textContainer setHeightTracksTextView:YES];
  47.     [_layoutManager addTextContainer:textContainer];
  48.     [textContainer release];
  49.  
  50.     // Create and configure NSTextView
  51.     textView = [[NSTextView allocWithZone:[self zone]] initWithFrame:frame textContainer:textContainer];
  52.     [textView setMinSize:frame.size];
  53.     [textView setMaxSize:frame.size];
  54.     [textView setHorizontallyResizable:NO];
  55.     [textView setVerticallyResizable:NO];
  56.     [textView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
  57.     [textView setSelectable:YES];
  58.     [textView setEditable:YES];
  59.     [textView setRichText:YES];
  60.     [textView setImportsGraphics:YES];
  61.     [textView setUsesFontPanel:YES];
  62.     [textView setUsesRuler:YES];
  63.     [aspectView addSubview:textView];
  64.     [textView release];
  65. }
  66.  
  67. - (void)didSwapIn {
  68.     [[[self aspectView] window] makeFirstResponder:[_layoutManager firstTextView]];
  69. }
  70.  
  71. @end
  72.