/* Copyright (C) 2002-2003, Jeffrey D. Argast. The authors make NO WARRANTY or representation, either express or implied, with respect to this software, its quality, accuracy, merchantability, or fitness for a particular purpose. This software is provided "AS IS", and you, its user, assume the entire risk as to its quality and accuracy. Permission is hereby granted to use, copy, modify, and distribute this software or portions thereof for any purpose, without fee, subject to these conditions: (1) If any part of the source code is distributed, then this statement must be included, with this copyright and no-warranty notice unaltered. (2) Permission for use of this software is granted only if the user accepts full responsibility for any undesirable consequences; the authors accept NO LIABILITY for damages of any kind. */ #import "EditSheetController.h" #import "AppUtils.h" @interface EditSheetController (PrivateMethods) - (void) sheetDidEnd: (NSWindow*) sheet returnCode: (int) returnCode contextInfo: (void*) contextInfo; @end @implementation EditSheetController - (id) init { self = [super init]; [NSBundle loadNibNamed:@"EditWindow" owner:self]; // Make the window scrollable in both horiz and vert directions // thereby turning off text wrap NSTextContainer* textContainer = [fTextView textContainer]; NSView* clipView = [fTextView superview]; NSScrollView* scrollView = (NSScrollView*) [clipView superview]; [scrollView setHasVerticalScroller:YES]; [scrollView setHasHorizontalScroller:YES]; [textContainer setContainerSize:NSMakeSize(1.0e7 /*BIG number*/, 1.0e7 /*BIG number*/)]; [textContainer setWidthTracksTextView:NO]; [textContainer setHeightTracksTextView:NO]; [fTextView setMaxSize:NSMakeSize(1.0e7 /*BIG number*/, 1.0e7 /*BIG number*/)]; [fTextView setHorizontallyResizable:YES]; [fTextView setVerticallyResizable:YES]; [fTextView setRichText:NO]; [fTextView setUsesRuler:NO]; [fTextView setImportsGraphics:NO]; // All of this crap is to put tab stops in place because if a tab occurs beyond the // last tab stop then the text breaks. Which is dumb but this works around it by // creating a buttload of tabstops. NSFont* fixedFont = [NSFont userFixedPitchFontOfSize:0]; NSParagraphStyle* defaultStyle = [NSParagraphStyle defaultParagraphStyle]; NSMutableParagraphStyle* newStyle = [defaultStyle mutableCopy]; NSMutableArray *tabStops = [NSMutableArray arrayWithCapacity:100]; int i; float widthOfTab = [fixedFont maximumAdvancement].width * 4.0; for (i = 1; i <= 100; i++) { NSTextTab *tab = [[NSTextTab alloc] initWithType:NSLeftTabStopType location:widthOfTab * i]; [tabStops addObject:tab]; [tab release]; } [newStyle setTabStops:tabStops]; NSMutableDictionary *textAttributes = [[[NSMutableDictionary alloc] initWithCapacity:2] autorelease]; [textAttributes setObject:fixedFont forKey:NSFontAttributeName]; [textAttributes setObject:newStyle forKey:NSParagraphStyleAttributeName]; [fTextView setTypingAttributes:textAttributes]; fStyle = [newStyle retain]; return self; } - (void) dealloc { [fStyle release]; [super dealloc]; } - (void) showSheet:(id)sender selector:(SEL)senderSelector withContent:(NSString*)contentString title:(NSString*)titleString { // logging the content string shows that there are no // extraneous line breaks that would cause the text to // wrap //NSLog (contentString); [fWindow setTitle:titleString]; [fTextView setString:contentString]; fSender = sender; fSelector = senderSelector; /* [NSApp beginSheet:fWindow modalForWindow:[NSApp mainWindow] modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:nil]; */ //[fWindow makeKeyAndOrderFront:self]; // I switched to modal dialog because I wanted undo/redo and I don't // know how to make that work with sheets. int retCode = [NSApp runModalForWindow:fWindow]; // This shows that the text view itself isn't adding any line breaks // to the string NSLog ([fTextView string]); if ( retCode == NSRunStoppedResponse ) { [fSender performSelector:fSelector withObject:[fTextView string]]; } } - (IBAction) okayButton: (id) sender { [fWindow orderOut:sender]; [NSApp stopModal]; // [NSApp endSheet:fWindow returnCode:1]; } - (IBAction) cancelButton: (id) sender { [fWindow orderOut:sender]; [NSApp abortModal]; // [NSApp endSheet:fWindow returnCode:0]; } @end @implementation EditSheetController (PrivateMethods) - (void) sheetDidEnd: (NSWindow*) sheet returnCode: (int) returnCode contextInfo: (void*) contextInfo { if ( returnCode == 1 ) { [fSender performSelector:fSelector withObject:[fTextView string]]; } } @end