This is Notepad.m in view mode; [Download] [Up]
// // Notepad.m // Copyright (c) 1990 by Jiro Nakamura // All rights reserved // // Handles a notepad, opens it, lets the user modify it, // and if anything changes, lets her or him save it before // closing it. // // by Jiro Nakamura (ac6y@vax5.cit.cornell.edu) // // RCS Information // Revision Number-> $Revision: 2.6 $ // Last Revised-> $Date: 90/10/27 17:53:35 $ // static char rcsid[] = "$Id: Notepad.m,v 2.6 90/10/27 17:53:35 jiro Exp Locker: jiro $"; #import "Notepad.h" #import "Global.h" #import "cass.h" // for NOTEPADICON #import <appkit/Form.h> // for Forms #import <appkit/TextField.h> #import <strings.h> // for strcpy // The minimum dimensions of the notepad window #define MIN_WIDTH 125.0 #define MIN_HEIGHT 100.0 @implementation Notepad /* Note: * This +new routine is never actually called... * So I have "open" doing the "initMoreStuff". * Garance/Dec 22/95 */ + new { self = [super new]; [self initMoreStuff]; return self; } - initMoreStuff { char dumbChar[5]; // dumb references to some static constants, just // to avoid warning messages from the compiler (Garance) dumbChar[0] = rcsid[0]; // dumb de dumb [super initMoreStuff]; [self setDelegate:self]; pageNumber = 1; return self; } - open:sender { static int oldPageNumber = 0; static char notepadFile[FILENAME_BUFFER], temp[FILENAME_BUFFER]; static BOOL alreadyInited = FALSE; if( !alreadyInited) { /* note that this works only because there is * only one instance of Notepad in the app. * "alreadyInited" is tracking the class, really, * and not the individual instance. * Garance/Dec 22/95 */ alreadyInited = TRUE; [self initMoreStuff]; [self placeWindow: [global notepadFrame]]; [self setTitle: "Notepad"]; [self setWindowIcon: NOTEPADICON]; } if( pageNumber < 1) pageNumber = 1; strcpy( notepadFile, [global notepadFile]); sprintf(temp, "%s.%d", notepadFile, pageNumber); strcpy(notepadFile, temp); #ifdef DEBUG fprintf(stderr,"Opening notepad on page %d.\n" "File opened is <%s>\n", pageNumber, notepadFile); #endif [pageNumberForm setIntValue: pageNumber at:0]; [filenameTextField setStringValue: notepadFile]; [self openWith: notepadFile]; if( oldPageNumber != pageNumber) { [self update]; oldPageNumber = pageNumber; } return self; } - close { [global saveThisWindowPosition: DEFAULTNOTEPADFRAME : self]; [super close]; return self; } - pageBackward: sender { pageNumber --; if( [self isDocEdited]) [self save]; [self open: self]; return self; } - pageForward: sender { pageNumber ++; if( [self isDocEdited]) [self save]; [self open: self]; return self; } - pageFormModified: sender { pageNumber = [pageNumberForm intValueAt: 0]; if( [self isDocEdited]) [self save]; [self open: self]; return self; } - windowWillResize: (id) sender toSize: (NXSize *) size { #ifdef DEBUG fprintf(stderr,"Window would have resized to %f x %f.\n", size->width, size->height); #endif if( size->width < MIN_WIDTH) size->width = MIN_WIDTH; if( size->height < MIN_HEIGHT) size->height = MIN_HEIGHT; #ifdef DEBUG fprintf(stderr,"Window will resize to %f x %f.\n", size->width, size->height); #endif return self; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.