home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / Utilities / FileSpy-1.1-MIHS / Document.m < prev    next >
Encoding:
Text File  |  1996-04-12  |  3.4 KB  |  136 lines

  1. /*
  2.  *   This sourcecode is part of FileSpy, a logfile observing utility.
  3.  *   Copyright (C) 1996  Felix Rauch
  4.  *
  5.  *   This program is free software; you can redistribute it and/or modify
  6.  *   it under the terms of the GNU General Public License as published by
  7.  *   the Free Software Foundation; either version 2 of the License, or
  8.  *   (at your option) any later version.
  9.  *   
  10.  *   Notice that this program may not be possessed, used, copied,
  11.  *   distributed or modified by people having to do with nuclear
  12.  *   weapons. See the file CONDITIONS for details.
  13.  *
  14.  *   This program is distributed in the hope that it will be useful,
  15.  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  *   GNU General Public License for more details.
  18.  *
  19.  *   You should have received a copy of the GNU General Public License
  20.  *   along with this program; if not, write to the Free Software
  21.  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  *
  23.  *   To contact the original author, try:
  24.  *   e-mail: Felix.Rauch@nice.ch
  25.  *   Traditional mail:    Felix Rauch
  26.  *            Sempacherstrasse 33
  27.  *            8032 Zurich
  28.  *            Switzerland
  29.  */
  30.  
  31. // Most of this has been taken from YapDocument.m
  32.  
  33. #import "Document.h"
  34.  
  35. #define MAXSIZE 1.0e38    // Maximum size of a text object
  36.  
  37. @implementation Document
  38.  
  39. + new:sender;
  40. {
  41.     id docWin;        /* Window belonging to this document. */
  42.     id textObj;        /* The text object we put in the window. */
  43.     NXRect textFrame;    /* The frame of the text object in our window */
  44.  
  45.     self = [[Document allocFromZone:[self newZone]] init];
  46.  
  47.     if (![NXApp loadNibSection:"Document.nib" owner:self withNames:NO fromZone:[self zone]]) {
  48.     NXLogError ("Can't find Document.nib!");    
  49.         [self free];
  50.     return nil;
  51.     }
  52.     
  53.     docWin = [document window];
  54.     [[document docView] getFrame:&textFrame];
  55.     [docWin setDelegate:sender];
  56.     textObj = [[Text alloc] initFrame:&textFrame];
  57.     [[document setDocView:textObj] free];
  58.     [document setAutoresizeSubviews:YES];
  59.     [textObj setVertResizable:YES];        // Grow down as you type
  60.     [textObj setHorizResizable:NO];        // But not sideways 
  61.     [textObj setAutosizing:NX_WIDTHSIZABLE];    // Size horizontally when resized
  62.     [textObj setMonoFont:YES];
  63.     [textObj setOpaque:YES];
  64.     [textObj setMinSize:&textFrame.size];
  65.     NX_WIDTH(&textFrame) = NX_HEIGHT(&textFrame) = MAXSIZE;
  66.     [textObj setMaxSize:&textFrame.size];    // Can grow
  67.     [textObj setSel:0:0];            // Set the selection
  68.     [textObj setDelegate:self];
  69.     [textObj sizeToFit];
  70.     [textObj setEditable:NO];
  71.  
  72.     
  73.     [self setDocument:document];
  74.     [self setWindow:docWin];            // make the new instance familiar with the window
  75.     return self;
  76. }
  77.  
  78. /*
  79.  * The next two methods allow us to cache/reuse zones.
  80.  */
  81. static id zoneList = nil;
  82.  
  83. + (NXZone *)newZone
  84. {
  85.     if (!zoneList || ![zoneList count]) {
  86.     return NXCreateZone(vm_page_size, vm_page_size, YES);
  87.     } else {
  88.     return (NXZone *)[zoneList removeLastObject];
  89.     }
  90. }
  91.  
  92. + (void)reuseZone:(NXZone *)aZone
  93. {
  94.     if (!zoneList) zoneList = [List new];
  95.     [zoneList addObject:(id)aZone];
  96. }
  97.  
  98.  
  99. - free
  100. {
  101.     NXZone *docZone = [self zone];
  102.     [super free];
  103.     [Document reuseZone:docZone];
  104.     return nil;
  105. }
  106.  
  107. - scrollView
  108. {
  109.     return document;
  110. }
  111.  
  112. - setDocument:doc
  113. {
  114.     document = doc;
  115.     return self;
  116. }
  117.  
  118. - setWindow:window
  119. {
  120.     myWin = window;
  121.     return self;
  122. }
  123.  
  124. - window
  125. {
  126.     return myWin;
  127. }
  128.  
  129. - moveWindowTo:(NXCoord)x:(NXCoord)y
  130. {
  131.     [myWin moveTo:x:y];
  132.     return self;
  133. }
  134.  
  135. @end
  136.