File:  [NeXTSTEP 3.3 examples] / Examples / AppKit / Draw / DrawPageLayout.m
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:48:37 2018 UTC (8 years, 1 month ago) by root
Branches: NeXT, MAIN
CVS tags: NeXTSTEP33, HEAD
Sample Programs from NeXSTEP 3.3

#import "draw.h"

@implementation DrawPageLayout
/*
 * PageLayout is overridden so that the user can set the margins of
 * the page.  This is important in a Draw program where the user
 * typically wants to maximize the drawable area on the page.
 *
 * The accessory view is used to add the additional fields, and
 * pickedUnits: is overridden so that the margin is displayed in the
 * currently selected units.  Note that the accessoryView is set
 * in InterfaceBuilder using the outlet mechanism!
 *
 * This can be used as an example of how to override Application Kit panels.
 */

- pickedUnits:sender
/*
 * Called when the user selects different units (e.g. cm or inches).
 * Must update the margin fields.
 */
{
    float old, new;

    [self convertOldFactor:&old newFactor:&new];
    [leftMargin setFloatValue:new * [leftMargin floatValue] / old];
    [rightMargin setFloatValue:new * [rightMargin floatValue] / old];
    [topMargin setFloatValue:new * [topMargin floatValue] / old];
    [bottomMargin setFloatValue:new * [bottomMargin floatValue] / old];

    return [super pickedUnits:sender];
}

- readPrintInfo
/*
 * Sets the margin fields from the Application-wide PrintInfo.
 */
{
    PrintInfo *pi;
    float conversion, dummy;
    NXCoord left, right, top, bottom;

    [super readPrintInfo];
    pi = [NXApp printInfo];
    [self convertOldFactor:&conversion newFactor:&dummy];
    [pi getMarginLeft:&left right:&right top:&top bottom:&bottom];
    [leftMargin setFloatValue:left * conversion];
    [rightMargin setFloatValue:right * conversion];
    [topMargin setFloatValue:top * conversion];
    [bottomMargin setFloatValue:bottom * conversion];

    return self;
}

- writePrintInfo
/*
 * Sets the margin values in the Application-wide PrintInfo from
 * the margin fields in the panel.
 */
{
    PrintInfo *pi;
    float conversion, dummy;

    [super writePrintInfo];
    pi = [NXApp printInfo];
    [self convertOldFactor:&conversion newFactor:&dummy];
    if (conversion) {
	[pi setMarginLeft:[leftMargin floatValue] / conversion
		    right:[rightMargin floatValue] / conversion
		      top:[topMargin floatValue] / conversion
		   bottom:[bottomMargin floatValue] / conversion];
    }

    return self;
}

/* outlet setting methods */

- setTopBotForm:anObject
{
    [anObject setTarget:ok];
    [anObject setAction:@selector(performClick:)];
    [anObject setNextText:width];
    topMargin = [anObject findCellWithTag:5];
    bottomMargin = [anObject findCellWithTag:6];
    return self;
}

- setSideForm:anObject
{
    [scale setNextText:anObject];
    [anObject setTarget:ok];
    [anObject setAction:@selector(performClick:)];
    leftMargin = [anObject findCellWithTag:3];
    rightMargin = [anObject findCellWithTag:4];
    return self;
}

@end


unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.