home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / Adroff2 / TextView.m < prev    next >
Encoding:
Text File  |  1991-10-29  |  2.2 KB  |  87 lines

  1. /*
  2. **  TextView.m, implementation of scrolling text stuff for TextLab.
  3. **  Copyright 1989 NeXT, Inc.  All Rights Reserved.
  4. **  Author: Bruce Blumberg
  5. **
  6. **  You may freely copy, distribute and reuse the code in this example.
  7. **  NeXT disclaims any warranty of any kind, expressed or implied, as to
  8. **  its fitness for any particular use.
  9. */
  10.  
  11.  
  12. #import <appkit/appkit.h>
  13. #import "TextView.h"
  14.  
  15. @implementation TextView:ScrollView
  16.  
  17. - initFrame:(const NXRect *)frameRect
  18. {
  19.     NXRect rect = {0.0, 0.0, 0.0, 0.0};
  20.     
  21.     /* initialize view */
  22.     [super initFrame:frameRect];
  23.     
  24.     /* specify scrollbars */
  25.     [[self setVertScrollerRequired:YES] setHorizScrollerRequired:NO];
  26.  
  27.     [self getContentSize:&(rect.size)];
  28.     theText = [self newText:&rect];
  29.     [self setDocView:theText];
  30.     [theText setSel:0 :0];    
  31.     
  32.     // The following two lines allow the resizing of the scrollview
  33.     // to be passed down to the docView (in this case, the text view 
  34.     // itself).
  35.  
  36.     [contentView setAutoresizeSubviews:YES];
  37.     [contentView setAutosizing:NX_HEIGHTSIZABLE | NX_WIDTHSIZABLE];
  38.  
  39.     // Create enclosing window and bring it upfront
  40.     [self makeEnclosingWindow:frameRect];
  41.     [[[window setTitle:"Untitled"] display] makeKeyAndOrderFront:self];
  42.  
  43.     return self;
  44. }
  45.  
  46. - makeEnclosingWindow:(const NXRect *)rect
  47. {
  48.     id      textWindow;
  49.     
  50.     textWindow = [[Window alloc] initContent:rect
  51.                  style:NX_TITLEDSTYLE
  52.                  backing:NX_BUFFERED
  53.                  buttonMask:NX_ALLBUTTONS
  54.                  defer:NO];
  55.     [textWindow setContentView:self];
  56.     [textWindow setBackgroundGray:NX_WHITE];
  57.     [textWindow setFreeWhenClosed:YES];
  58.     
  59.     return self;
  60. }
  61.     
  62. - newText:(const NXRect *)frameRect
  63. {
  64.     id    text;
  65.     NXSize aSize = {1.0E38, 1.0E38};
  66.  
  67.     text = [[Text alloc] initFrame:frameRect
  68.                  text:NULL
  69.              alignment:NX_LEFTALIGNED];
  70.     [text setOpaque:YES];
  71.     [[[[[text notifyAncestorWhenFrameChanged:YES]
  72.                 setVertResizable:YES]
  73.                     setHorizResizable:NO]
  74.                     setMonoFont:NO]
  75.                         setDelegate:self];
  76.   
  77.     [text setMinSize:&(frameRect->size)];
  78.     [text setMaxSize:&aSize];
  79.     [text setAutosizing:NX_HEIGHTSIZABLE | NX_WIDTHSIZABLE];
  80.     
  81.     [text setCharFilter:NXEditorFilter];
  82.    
  83.     return text;
  84. }
  85.  
  86. @end
  87.