Skip navigation.
 
mlrefreshing after a zooming an nstextview
FROM : Matthew Weinstein
DATE : Sun May 01 17:19:09 2005

Dear cocoa-nuts,

After searching a while I found code to help zoom a text view. I do it
as shown below. It does work; the text zooms. But the
nstextview/scrollview doesn't adjust the rows at that point. How do I
tell it to recalculate and redraw everything. I've tried a number of
notifications and calls, but none seem to take. 1000 thanks in advance.

Here are the notifications I post:

    [self setZoom: [gPrefBoss zoomWindowFactor]];
    [[NSNotificationCenter defaultCenter] postNotification:
[NSNotification notificationWithName:
@"NSTextViewDidChangeTypingAttributesNotification" object: theDoc]];
    [[NSNotificationCenter defaultCenter] postNotification:
[NSNotification notificationWithName: @"NSWindowDidResizeNotification"
object: myWindow]];

Here is my implementation of zoom:

@implementation NSView (ScaleUtilities)

const NSSize unitSize = { 1.0, 1.0 };

// This method makes the scaling of the receiver equal to the window's
// base coordinate system.
- (void) resetScaling { [self scaleUnitSquareToSize: [self convertSize:
unitSize fromView: nil]];  }

    // This method sets the scale in absolute terms.
- (void) setScale:(NSSize) newScale
{
    [self resetScaling];  // First, match our scaling to the window's
coordinate system
    [self scaleUnitSquareToSize:newScale]; // Then, set the scale.
}

// This method returns the scale of the receiver's coordinate system,
relative to
// the window's base coordinate system.
- (NSSize) scale { return [self convertSize:unitSize toView:nil]; }

    // Use these if you'd rather work with percentages.
- (float) scalePercent { return [self scale].width * 100; }

- (void) setScalePercent:(float) scale
{
    scale = scale/100.0;
    [self setScale:NSMakeSize(scale, scale)];
    [self setNeedsDisplay:YES];
}


@end

Matthew Weinstein
Associate Professor of Science Education
Kent State University
404 J White Hall
Kent, OH 44242

<email_removed>
330 672-0653

Related mailsAuthorDate
No related mails found.