home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Examples / AppKit / TextSizingExample / TwoColumnsAspect.m < prev    next >
Text File  |  1996-04-17  |  4KB  |  90 lines

  1. /*
  2.         TwoColumnsAspect.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 "TwoColumnsAspect.h"
  13. #import "Controller.h"
  14.  
  15. @implementation TwoColumnsAspect
  16.  
  17. - (void)dealloc {
  18.     [[[self controller] textStorage] removeLayoutManager:_layoutManager];
  19.     [_layoutManager release];
  20.     [super dealloc];
  21. }
  22.  
  23. - (NSString *)aspectName {
  24.     return NSLocalizedString(@"Two Column Text", @"Display name for TwoColumnAspect.");
  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 first NSTextContainer
  44.     textContainer = [[NSTextContainer allocWithZone:[self zone]] initWithContainerSize:NSMakeSize(200.0, frame.size.height)];
  45.     [textContainer setWidthTracksTextView:YES];
  46.     [textContainer setHeightTracksTextView:YES];
  47.     [_layoutManager addTextContainer:textContainer];
  48.     [textContainer release];
  49.  
  50.     // Create and configure first NSTextView
  51.     textView = [[NSTextView allocWithZone:[self zone]] initWithFrame:NSMakeRect(frame.origin.x, frame.origin.y, 200.0, frame.size.height) textContainer:textContainer];
  52.     [textView setMinSize:NSMakeSize(200.0, frame.size.height)];
  53.     [textView setMaxSize:NSMakeSize(200.0, frame.size.height)];
  54.     [textView setHorizontallyResizable:NO];
  55.     [textView setVerticallyResizable:NO];
  56.     [textView setAutoresizingMask:(NSViewMaxXMargin | 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.     // Create and configure second NSTextContainer
  67.     textContainer = [[NSTextContainer allocWithZone:[self zone]] initWithContainerSize:NSMakeSize(frame.size.width - 200.0 - 8.0, frame.size.height)];
  68.     [textContainer setWidthTracksTextView:YES];
  69.     [textContainer setHeightTracksTextView:YES];
  70.     [_layoutManager addTextContainer:textContainer];
  71.     [textContainer release];
  72.  
  73.     // Create and configure second NSTextView
  74.     textView = [[NSTextView allocWithZone:[self zone]] initWithFrame:NSMakeRect(frame.origin.x + 200.0 + 8.0, frame.origin.y, frame.size.width - 200.0 - 8.0, frame.size.height) textContainer:textContainer];
  75.     [textView setMinSize:NSMakeSize(frame.size.width - 200.0 - 8.0, frame.size.height)];
  76.     [textView setMaxSize:NSMakeSize(frame.size.width - 200.0 - 8.0, frame.size.height)];
  77.     [textView setHorizontallyResizable:NO];
  78.     [textView setVerticallyResizable:NO];
  79.     [textView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
  80.     // Don't bother configuring the shared attributes of the text view since we already did it for the first one.
  81.     [aspectView addSubview:textView];
  82.     [textView release];
  83. }
  84.  
  85. - (void)didSwapIn {
  86.     [[[self aspectView] window] makeFirstResponder:[_layoutManager firstTextView]];
  87. }
  88.  
  89. @end
  90.