ftp.nice.ch/peanuts/GeneralData/Documents/books/AlexNeXTSTEPSource.tar.gz#/NSProgramming/Chapter9_Text/Scroll/Scroll.m

This is Scroll.m in view mode; [Download] [Up]

#import <appkit/appkit.h>

// minimal program to demonstrate
// a text object and scrolling

main()
{
	id NXApp = [Application new];
	id theWindow;
	id theMenu;
	id theText; 
	id theScrollView;
	NXRect theRect;
	NXSize theSize;
	id otherWindow, otherText;
	NXSize otherSize;

	// create the window
	NXSetRect(&theRect, 200.0, 300.0, 350.0, 150.0);
	theWindow = [ [Window alloc]
		initContent:&theRect
		style: NX_TITLEDSTYLE
		backing:NX_BUFFERED
		buttonMask:NX_MINIATURIZEBUTTONMASK
		defer:YES];
	[theWindow setBackgroundGray:NX_WHITE];

	// create a scrollview
	NXSetRect(&theRect, 0.0, 0.0, 350.0, 150.0);
	theScrollView = [ [ScrollView alloc]
		initFrame:&theRect];
	[theScrollView
		setVertScrollerRequired:YES];
	[theScrollView
		setHorizScrollerRequired:NO];
	[ [theWindow contentView]
		addSubview :theScrollView];
	
	// get the size of the content view
	[theScrollView getContentSize:&theSize];

	// create another text object
	NXSetRect(&theRect, 0.0, 0.0,
		theSize.width, theSize.height);
	theText = [ [Text alloc] initFrame:&theRect
		text:"Text in scrollview"
		alignment:NX_LEFTALIGNED];
	[theText setOpaque:YES];
	// notify superview when frame
	// rectangle changes -- allows scrollview
	// to update the scrollers
	[theText notifyAncestorWhenFrameChanged:YES];
	[theText setVertResizable:YES];
	[theText setHorizResizable:NO];
	// select all the text

	// create min and max size of text
	theSize.width = 0.0;
	[theText setMinSize:&theSize];
	theSize.height = 1000000;
	[theText setMaxSize:&theSize];

	// set the text as docview of scrollview
	[theScrollView setDocView:theText];

	// create other window
	NXSetRect(&theRect, 100.0, 100.0, 350.0, 150.0);
	otherWindow = [ [Window alloc]
		initContent:&theRect
		style: NX_TITLEDSTYLE
		backing:NX_BUFFERED
		buttonMask:NX_MINIATURIZEBUTTONMASK
		defer:YES];
	[theWindow setBackgroundGray:NX_WHITE];

	// create other text
	NXSetRect(&theRect, 0.0, 0.0, 350.0, 150.0);
	otherText = [ [Text alloc]
		initFrame:&theRect
		text:"Text without scrollview"
		alignment:NX_LEFTALIGNED];
	[otherText setOpaque:YES];
	[ [otherWindow contentView]
		addSubview:otherText];

	// create min and max size of text
	otherSize.width = 0.0;
	[otherText setMinSize:&otherSize];
	otherSize.height = 1000000;
	[theText setMaxSize:&otherSize];

	// create the menu
	theMenu = [ [Menu alloc]
		initTitle: [NXApp appName] ];
	[theMenu addItem:"Quit"
		action:@selector(terminate:)
		keyEquivalent:'q'];
	[theMenu sizeToFit];
	[NXApp setMainMenu:theMenu];

	// display both windows
	[theWindow makeKeyAndOrderFront:nil];
	// set the selection in the text
	[theText setSel:0 :0];
	[otherWindow orderFront:nil];

	// Enter event loop
	[NXApp run];
}

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.